Please format your code above.
Have a look at these links:
SendingMultipleData \ Learning \ Wiring
Receive Multiple Sensor Information from Arduino to Processing - Processing 2.x and 3.x Forum
Reading multiple sensors is common. You need to implement a first design based on examples that are readily available in previous posts or in the web.
looking at your ino code, you could do:
Serial.write(val1); // Send the value1
Serial.write(','); //Need to check this or used the int equivalent
Serial.write(val2); // Send the value2
Serial.write(';');
So the data that you stream will look like this: val1,val2;
. In other words, your values are separated by a ‘,’ char and your data stream ends with a ‘;’ character. In Processing, you read your serial buffer until the ‘;’ character and THEN your processed your data, splitting it at the ‘,’ and ‘;’ character and extracting val1
and val2
.
Kf