serial object: transmit byte (0-255) data only?
Hello!
I'm working on a project where I transmit data from Max to Arduino to change the RGB values of a multicolor LED.
The multicolor led I'm using reads RGB values in bytes 0-255, but if the only data are numbers in that same byte range, its tricky for me (not an expert) to parse it to the R, G, and B values individually, since the possible range of values I can input is the same as the data needed to change the RGB values. I can't send a different outlier value from Max to Arduino for an Serial.read if statement to recognize and parse the previous value to the R, G, or B.
I'm formatting the message to the serial object as 3 ints ("0 0 255" for blue) and I'm attempting to in Arduino use an array to store three numbers, parse them to the R G and B values, then reset for the next three values coming in, but I'm worried that won't work if it's getting a lot of values in quickly (mousing on a swatch object for example).
Is there any way to send different data that I can use to parse to R G and B from the serial object, or is it only single integers 0-255.
Thanks!
Jacob
LED RGB Max to arduino was really posted many times on the forum.
in few words, you send 3 ints and line feed at the end.
In arduino use parseInt to capture 3 ints and assign them to your values.
void setup() {Serial.begin(57600);}
void loop() {if(Serial.available() > 0) {
int R = Serial.parseInt();
int G = Serial.parseInt();
int B = Serial.parseInt();
if (Serial.read() == '\n') { here you write what you want with that 3 values }
}}
in Max :

You can increase serial baud rate if you feel it needs to be faster.