We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm a processing pivot. I have a problem I have a value taken from Arduino, and I visualize it in a graph, but I would also like to be able to visualize it through a numerical table. How can I do? thank you!
import processing.serial.*;
import grafica.*;
Serial myPort; // The serial port:
float val;//i datiricevutidalla porta seriale
int xPos=0;
//Stringa di input dalla porta seriale:
int lf = 10; // ASCII linefeed
GPlot plot1, plot2;
void setup() {
size(440, 520);
// Create the first plot Crea il primo grafico
plot1 = new GPlot(this);
plot1.setPos(0, 0);
plot1.setMar(0, 100, 0,100);
plot1.setDim(300, 300);
plot1.setAxesOffset(4);
plot1.setTicksLength(4);
// Create the second plot with the same dimensions
//Crea il secondo grafico con le stesse dimensioni
plot2 = new GPlot(this);
// Prepare the points Prepara i punti
int val =0;
GPointsArray points = new GPointsArray(val);
for (int i = 15; i < 13; i++) {
points.add(i, 20 + 10*noise(i*0.1));
if(xPos==13){
}
}
// Set the points, the title and the axis labels
// Imposta i punti, il titolo e le etichette degli assi
plot1.setPoints(points);
plot1.setTitleText("Temperature");
plot1.getYAxis().setAxisLabelText("MASSA ARIA (?)");
plot1.getXAxis().setAxisLabelText("APERTURA VALVOLA (mm)");
plot1.activatePanning();
myPort = new Serial(this, "com3", 9600);
myPort.bufferUntil(lf);
}
void draw() {
background(255);
println(val);
fill(0);
text("val "+val,200,450);
//Disegna la prima trama
plot1.beginDraw();
plot1.drawBox();
plot1.drawXAxis();
plot1.drawYAxis();
plot1.drawTitle();
//plot1.drawPoints();//pallinorosso sul valore
plot1.drawGridLines(GPlot.BOTH);
plot1.drawLines();
plot1.endDraw();
}
void serialEvent (Serial myPort) {
// // get the ASCII string:
// // ottiene la stringa ASCII:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// // trim off any whitespace:
inString = trim(inString);
val = float(inString);
println(val);
}
}
void mousePressed(){
GPoint lastPoint = plot2.getPointsRef().getLastPoint();
if (lastPoint == null) {
plot1.addPoint(xPos, +val, "(" + str(xPos) + " , " + str(val) + ")");
}
else if (!lastPoint.isValid() || sq(lastPoint.getX() - xPos) + sq(lastPoint.getY() + val) > 2500) {
}
if( mouseButton == LEFT ) xPos+=1;
fill(0);
text ("val"+val,200,480);
}
Answers
for plotting see latest comments here:
https://forum.processing.org/two/discussion/25248/plotting-data/p1
this won't work:
see reference under
for
, you wantfor (int i = 0; i < 13; i++) {
for a simple table output see here:
> Thanks Chrisir for your advice, but I do not understand how to play "val" both with the graph and at the same time reproduced in a table ....>
just make your window more wide with
size
and then place the table right from the graph (using higher x-values).Where you say
points.add(i, 20 + 10*noise(i*0.1));
also put the same value into my ArrayList (which needs another name like pointsTable)Ciao, grazie per il tuo interessamento, il grafico usa le cordinate "val e xPos( aggiornato ad ogni "mousePressed"), non capisco come nello stesso momento compilare la tabella con "val" aggiornati ad ogni azione di "mousePressed"... Grazie...
non capisco
English please
here, when you click the mouse, values are plotted AND in the table
sorry........
I am a young Italian and with English I still do a bit of effort and not to write oddities I use a translator ..... your sketch works, now I try to implement it to the sketch of the chart and I see what happens ....... Thanks again
You're welcome!
My intention is to see "val" with the graph of my sketch and complete it with the table that suggested me.
I keep you informed thanks
thanks
the sketch works only (and not always) only at the first mouse pressure .... after I write incorrect values and even if various "val" the value in the table does not match .....
first the mouse clicks are just a simulation since my arduino is not on
second, press ctrl-t in processing and then show your entire code here so we can have a look.
found!!! I deleted in line 49...
val= float(mouseX);
Congratulations!