question on grafica

edited March 2018 in Arduino

Hi, I'm a newbie, I'm trying to change the example in "grafica". In the "multipoint" example the "Plot2" can be deleted and rewritten with key pressed. Is it possible to save the first graph and draw the second one? Is it also possible to write down the points in a table? Thank you

Tagged:

Answers

  • sorry for example of multy plots

  • do not reset but new chart

  • Is this example available in the grafica's website? Can you provide a link to it? Or even better, provide an MCVE showing your problem.

    Kf

  • edited March 2018

    @brugola -- The Processing(Java) grafica library doesn't come with example called "multipoint" -- it has MovingPoints, MultiplePanels, and MultiplePlots. Are you talking about one of these?

    Edit -- oh, that's what you meant by multy plots.

    Okay. So your question is about the example: MultiplePlots

    Here is the code:

      // Reset the points if the user pressed the space bar
      if (keyPressed && key == ' ') {
        plot2.setPoints(new GPointsArray());
      }
    

    And you want to save the points from plot2 before you replace them with a new GPointsArray -- is that right?

    I think you could either write those points into a Table at the same time you are adding them to plot2, or you could get the GPointsArray from plot2 and loop through it to retrieve the values, writing each into a Table. All the methods of GPlot and GPointsArray are here....

    I agree with @kfrajer that a simple sketch demonstrating what you are trying to do would help forum members trying to give you better advice.

  • Hello. Thank you for your valuable help. what I'd like to do is draw the graph and at the same time fill in the table with each mouse pressed. When I press the "z" key, start drawing the graph again (without deleting the first track) and compiling a new table. Or save the file of the first graph and its table, to recall only the graph line and the table and make it appear on a new sketch. Being a young novice kid with processing all your help for me is very welcome. Thank you!!!

    import processing.serial.*; 
    import controlP5.*;    // import controlP5 library
    import grafica.*;
    ControlP5 controlP5;   // controlP5 object
                   ArrayList<PVector> punto = new ArrayList();
    Serial myPort;    // The serial port: 
    PFont f;     // The display font: 
    String inString;  // Input string from serial port: 
    int lf = 10;      // ASCII linefeed 
    float deg, val;
    int myColorBackground = color(0,0,0);
    Knob myKnob1,myKnob2,myKnob3,myKnob4;
                    int i; 
                    int y;
    int knobValue = 100;
    int xPos=0;
    GPlot plot1, plot2;
     int a=1;
      int x=0;
    
    
    
    void setup() { 
    size(1350,750);
    PFont  f= loadFont ("AgencyFB-Bold-25.vlw");
    textFont(f);
    
    myPort = new Serial(this, "com3", 9600);
    myPort.bufferUntil(lf);
    {
    smooth();  //ControlP5
    controlP5 = new ControlP5(this);   //ControlP5
    myKnob1 = controlP5.addKnob("1")
    .setRange(0,5)
    .setValue(0)
    .setPosition(700,10)//posizione 605
    .setTickMarkLength(10)
    .setColorForeground(color(#FF0004))//colore cursore
    .setColorBackground(color(255))//colore sfondo
    .setColorValueLabel(color(0))//colore numeri//label etichetta
    .setColorActive(color(#6AFA05))
    .setDragDirection(Knob.VERTICAL)
    .lock()
    .setSize(150,150)//dimensioni
    . setDecimalPrecision(2) //numero dopo la virgola
    ;
    myKnob1 .getCaptionLabel()
    . setFont(f);
    myKnob1.getValueLabel()
    .setFont(f)
    ;
    myKnob2 = controlP5.addKnob("2")
    .setRange(0,500)
    .setValue(0)
    .setPosition(900,10)
    .setColorForeground(color(#FF0004))//colore cursore
    .setColorBackground(color(255))//colore sfondo
    .setColorValueLabel(color(0))//colore numeri//label etichetta
    .setColorActive(color(#6AFA05))
    .setDragDirection(Knob.VERTICAL)
    .lock()
    .setSize(150,150)//dimensioni
    .setDecimalPrecision(2) //numero dopo la virgola
    .setTickMarkLength(10) 
    ;
    
    myKnob2 .getCaptionLabel()
    . setFont(f);
    myKnob2.getValueLabel()
    .setFont(f)
    ;
    
    myKnob3 = controlP5.addKnob("3")
    .setRange(0,500)
    .setValue(1)
    .setPosition(1100,10)
    .setColorForeground(color(#FF0004))//colore cursore
    .setColorBackground(color(255))//colore sfondo
    .setColorValueLabel(color(0))//colore numeri//label etichetta
    .setColorActive(color(#6AFA05))
    .setDragDirection(Knob.VERTICAL)
    .lock()
    .setSize(150,150)//dimensioni
    .setDecimalPrecision(2) //numero dopo la virgola
    .setTickMarkLength(10)
    ;
    
    
    myKnob3 .getCaptionLabel()
    . setFont(f);
    myKnob3.getValueLabel()
    .setFont(f)
    
    ;
    
    
    
    plot1 = new GPlot(this);
    plot1.setPos(200,200);//posizione
    plot1.setMar(0, 100, 0,100);
    plot1.setDim(1000, 480);//dimensione
    plot1.setAxesOffset(4);
    plot1.setTicksLength(4);
    
      // Create the second plot with the same dimensions 
    
    plot2 = new GPlot(this);
    
    
      // Prepare the points Prepara i punti
    int myKnob1 =0;
    GPointsArray points = new GPointsArray(myKnob1);
    
    for (int i = 0; i < 13; i++) {
    
    if(xPos==13){
    }
    }
    plot1.setPoints(points);
    
    plot1.getYAxis().setAxisLabelText("MASSA ARIA (?)");
    plot1.getXAxis().setAxisLabelText("APERTURA VALVOLA (mm)");
    
    
    // Attiva il panning (solo per il primo grafico)
    plot1.activatePanning();
    
    } 
    }
    
    
    
    void serialEvent(Serial p) { 
    inString = p.readString(); 
    char primo=inString.charAt(0);  // primo carattere
    String cifra=inString.substring(1);  // da secondo carattere in poi
    float val=parseFloat(cifra);          // valore da 0-255 o 0-1023, non sò cosa spedisce arduino
    
    
    print("val=");    println(val);
    
    inString = trim(inString);
    
    //    // converte in int e mappa all'altezza dello schermo: 
    
    
    switch(primo) { 
    case ('A'): myKnob1.setValue(val);
    break;
    case ('B'): myKnob2.setValue(val);
    break;
    case ('C'): myKnob3.setValue(val);
    break;
    }
    }
    
    
    
    
    void draw() { 
    
    
    background(255);
    fill(0);
    rect(680,6,600,180,10);
    // fill(0);
    rect(380,105,200,50,10);
     // show data 
    rect(55,350,118,25,10);
    rect(55,380,30,325,10);
    int y=400;//asse y
    
    for (PVector myKnob1 : punto) {
    
    { 
    
    fill(255);
    textSize(22);
    textSize(18);
    text("0",60,400);
    text("1",60,420);
    text("2",60,440);
    text("3",60,460);
    text("4",60,480);
    text("5",60,500);
    text("6",60,520);
    text("7",60,540);
    text("8",60,560);
    text("9",60,580);
    text("10",60,600);
    text("11",60,620);
    text("12",60,640);
    text("13",60,660);
    text("14",60,680);
    text("15",60,700);
    }
    
    fill(0);
    text(+myKnob1.y, 90, y);
    y+=20; //next line
    
    
    }
    
    { 
    
    
    //Disegna la prima trama 
    plot1.beginDraw();
    plot1.drawBox();
    plot1.drawXAxis();
    plot1.drawYAxis();
    plot1.drawTitle();
    
    plot1.drawGridLines(GPlot.BOTH);
    plot1.drawLines();
    plot1.endDraw();
    
    textSize(25);
    
    
    fill(255);
    text(( myKnob2.getValue()- myKnob3.getValue()),400,140);
    
    }
    {
    textSize(50);
    fill(0);
    
    
    
    
    }
    }
    
    
    
    
    
    
    
    
    void mousePressed(){
    
    GPoint lastPoint = plot2.getPointsRef().getLastPoint();
    
    if (lastPoint == null) {
    
    plot1.addPoint(xPos, +myKnob1.getValue(), "(" + str(xPos) + " , " + str(myKnob1.getValue()) + ")");
    
    } 
    else if (!lastPoint.isValid() || sq(lastPoint.getX() - xPos) + sq(lastPoint.getY() + myKnob1.getValue()) > 2500) {
    }
    
     // Reset the points if the user pressed the space bar
    if (keyPressed && key == ' ') {
    plot1.setPoints(new GPointsArray());
    }
    
    
    
    if( mouseButton == LEFT ) xPos+=1; 
    
    
    {
    punto.add(new PVector(i, myKnob1.getValue()));
    a++;
    }
    }
    
  • saving the points of the first table to be able to recall and draw on a chart?

Sign In or Register to comment.