Hi everyone, i am working with processing and arduino. I am trying to pass via serial method a String “x;y” where x and y are integers from arduino to Processing. Then i want to plot on processing the x and y separately, but i can’t accomplish this since y is always zero. Someone can help?
processing:
Serial myPort; // The serial port
String coor;
int[] x = new int[width];
int[] y = new int[height];
int i = 0;
void setup() {
// List all the available serial ports:
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[0], 115200);
size(600, 600);
background(255);
}
void draw() {
while (myPort.available() > 0) {
String inBuffer = myPort.readString();
if (inBuffer != null) {
int[] coor = int(split(inBuffer, ';'));
x[i] = coor[0];
y[i] = coor[1];
println(inBuffer);
println(coor[1]);
i++;
}
}
}
arduino:
void setup() {
Serial.begin(115200);
Serial.println();
}
void loop() {
int x = random(0, 251);
int y = random(0, 361);
Serial.print(x);
Serial.write(';');
Serial.println(y);
delay(1000);
}