The next code ca be 8 graph signals of arduino (voltaje, temperatura etc), Ty for all participates in this forum
import processing.serial.Serial;
import grafica.*;
import java.util.Random;
public GPlot plot2 ;
static final int PORT_INDEX = 0, BAUDS = 9600;
int i=0;
int[] vals = {};
//float[] vals = {};
GPointsArray points2 = new GPointsArray();
GPointsArray points3 = new GPointsArray();
GPointsArray points4 = new GPointsArray();
GPointsArray points5 = new GPointsArray();
GPointsArray points6 = new GPointsArray();
GPointsArray points7 = new GPointsArray();
GPointsArray points8 = new GPointsArray();
void setup() {
//vals=new int[6];
size(850, 660);
noLoop();
final String[] ports = Serial.list();
printArray(ports);
new Serial(this, ports[PORT_INDEX], BAUDS).bufferUntil(ENTER);
plot2 = new GPlot(this);
plot2.setPos(5, 5);
plot2.setDim(550, 550);
plot2.getTitle().setText("Posicion");
plot2.getXAxis().getAxisLabel().setText("X");
plot2.getYAxis().getAxisLabel().setText("Y");
plot2.setLineWidth(1.5);
//
plot2.addLayer("layer 2", points2);
plot2.getLayer("layer 2").setLineColor(color(150, 150, 255));
plot2.getLayer("layer 2").setLineWidth(1.5);
//
plot2.addLayer("layer 3", points3);
plot2.getLayer("layer 3").setLineColor(color(150, 150, 255));
plot2.getLayer("layer 3").setLineWidth(1.5);
//
plot2.addLayer("layer 4", points4);
plot2.getLayer("layer 4").setLineColor(color(150, 150, 255));
plot2.getLayer("layer 4").setLineWidth(1.5);
//
plot2.addLayer("layer 5", points5);
plot2.getLayer("layer 5").setLineColor(color(150, 150, 255));
plot2.getLayer("layer 5").setLineWidth(1.5);
//
plot2.addLayer("layer 6", points6);
plot2.getLayer("layer 6").setLineColor(color(150, 150, 255));
plot2.getLayer("layer 6").setLineWidth(1.5);
//
plot2.addLayer("layer 7", points7);
plot2.getLayer("layer 7").setLineColor(color(150, 150, 255));
plot2.getLayer("layer 7").setLineWidth(1.5);
//
plot2.addLayer("layer 8", points8);
plot2.getLayer("layer 8").setLineColor(color(150, 150, 255));
plot2.getLayer("layer 8").setLineWidth(1.5);
//
plot2.activatePanning();
plot2.activateZooming(1.2, CENTER, CENTER);
plot2.activateReset();
}
void draw() {
// println(points1a);
// Draw the plot
plot2.beginDraw();
plot2.drawBackground();
plot2.drawBox();
plot2.drawXAxis();
plot2.drawYAxis();
plot2.drawTitle();
plot2.drawGridLines(GPlot.CTRLMOD );
plot2.drawLines();
if (vals.length >= 1) {
i++;
plot2.addPoint(i, vals[0]);
if (vals.length >= 2) {
plot2.addPoint(Point(i, vals[1]), "layer 2");
if (vals.length >= 3) {
plot2.addPoint(Point(i, vals[2]), "layer 3");
if (vals.length >= 4) {
plot2.addPoint(Point(i, vals[3]), "layer 4");
if (vals.length >= 5) {
plot2.addPoint(Point(i, vals[4]), "layer 5");
if (vals.length >= 6) {
plot2.addPoint(Point(i, vals[5]), "layer 6");
if (vals.length >= 7) {
plot2.addPoint(Point(i, vals[6]), "layer 7");
if (vals.length >= 8) {
plot2.addPoint(Point(i, vals[7]), "layer 8");
}
}
}
}
}
}
}
}
plot2.endDraw();
}
void serialEvent(final Serial s) {
vals = int(splitTokens(s.readString()));
//vals = float(splitTokens(s.readString()));
redraw = true;
}
GPoint Point(float i, float n) {
return new GPoint(i, n);
}