Sorry if this is a repost I tried briefly searching the forum but google wasn't been helpful so maybe ye can be
I'm trying to graph a signal that is inputed through the serial port
i found this code on the internet
// Graphing sketch
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
void setup () {
// set the window size:
size(400, 300);
println(Serial.list());
myPort = new Serial(this, Serial.list()[30], 9600);
myPort.bufferUntil('\n');
// set inital background:
background(0);
}
void draw () {
// everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);
// draw the line:
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
// increment the horizontal position:
xPos++;
}
}
}
this code is perfect but my problem with this display is that the signal will loop around at the end of the window and begin to write over itself
instead i would like the input to stay on either the left or right of the screen (probably left is easiest as it's x position pixel is 0) and that the previous data is shifted to the other side