Hi,
I'm having trouble getting Arduino to handle multiple incoming variables via serial communication (from Max/MSP) and am in serious need of help! My project includes outputting "lists" of variables to the arduino, including an "identifier" [0 - 3], along with an integer that I aim to assign to a variable within Arduino.
I stumbled upon this thread concerning the exact same topic, however the OP never explained how he tackled the problem:
For those who know how to use Max, here is my problem:
I'm not too show how to format the information before sending it over serial.
And for the Arduino-ers:
How do I handle multiple corresponding variables to ensure the information is a) recognized, and b) stored for use.
Here is a sample of the code I'm using to "handle" the data:
if (Serial.available() > 1){ //if 2 bytes available in the Serial buffer...
for (int i=0; i<2; i++) { // for each byte
bufferArray[ i ] = Serial.read(); // put into array
output = 1; // show new data has been recieved
}
}
if (output != 0) // if new bytes have been recieved
{
rowNumber = bufferArray[0]; // store first byte as "identifier"
rowBinary = bufferArray[1]; // store second byte as "value"
output = 0;
}
if (rowNumber == 0){
ledRow1 = rowBinary;
}
if (rowNumber == 1){
ledRow2 = rowBinary;
}
if (rowNumber == 2){
ledRow3 = rowBinary;
}
if (rowNumber == 3){
ledRow4 = rowBinary;
}
Any help would be greatly appreciated!
Thanks,
Ben K
Last Edit: Slight change in code, thanks PaulS!