Hi. I am pretty new to processing so bear with me for silly mistakes.I am trying to draw a trace of data received on serial port. I am able to receive it but i am not able to draw in using line. It just seems to not respond. The code is following which is derived form code i found online
import processing.serial.*;
Serial myPort; // Create object from Serial class
float val, screen_increment, old_x=0, old_y=0; // Data received from the serial port
String inString; // Input string from serial port
void setup()
{
size(1000, 600);
String portName = Serial.list()[2];//Set the Serial port COM
myPort = new Serial(this, portName, 9600);//Set up the serial port
myPort.bufferUntil('\n');//read in data until a line feed, so the arduino must do a println
background(208,24,24);//make the background that cool blood red
}//setup
void draw()
{
//nothing in here, this is kind of like the void loop in arduino
}
void serialEvent(Serial myPort) { //this is called whenever data is sent over by the arduino
inString = myPort.readString();//read in the new data, and store in inString
inString = trim(inString);//get rid of any crap that isn't numbers, like the line feed
val = float(inString);//convert the string into a number we can use
val=map(val,0,4096,0,600);
strokeWeight(5);//beef up our white line
stroke(255, 255, 255);//make the line white
//drawing the line
println(old_x,old_y,screen_increment,600-val);
line(old_x, old_y, screen_increment, 600-val);
//store the current x, y as the old x,y, so it is used next time
old_x = screen_increment;
old_y = 600-val;
//increment the x coordinate, you can play with this value to speed things up
screen_increment=screen_increment+2;
//this is needed to reset things when the line crashes into the end of the screen
if(screen_increment>(1000)){
background(208,24,24); //refresh the screen, erases everything
screen_increment=-50; //make the increment back to 0,
//but used 50, so it sweeps better into the screen
//reset the old x,y values
old_x = -50;
old_y = 0;
}
}
SInce i have added a println the output of the code println(old_x,old_y,screen_increment,600-val); is following which seems correct to me
0.0 0.0 0.0 302.9297
0.0 302.9297 2.0 303.8086
2.0 303.8086 4.0 300.29297
4.0 300.29297 6.0 297.36328
6.0 297.36328 8.0 295.60547
8.0 295.60547 10.0 294.87305
10.0 294.87305 12.0 294.14062
12.0 294.14062 14.0 294.87305
14.0 294.87305 16.0 296.77734
All I see is blank red screen
Please Help