I know this has been asked before, but I'm new to Arduino and Processing, and I'm trying to take this step by step.
I would like to pass an RGB value from processing, into Arduino via the Serial.Write/Read.
I have my Processing as:
void draw(){
//orange colour in RGB values
color _rgbColor = color(255, 40, 0);
//convert colour into hex
String _hexColor = hex(_rgbColor, 6);
//convert colour into binary
String _binaryColor = binary(_rgbColor);
//pass colour to port
myPort.write(_hexColor);
delay(500);
}
I assume I can just pass the HEX value straight across, right?
First problem I get is that I can't debug what my Arduino device is getting (when I run the Processing program, the Serial Monitor wont work. Seems like I can only use one or the other). I can print the myPort.read within my Processing after the delay, and I get:
-1
So I'm not quite sure what I'm doing wrong there.
On the Arduino side, I'm using Serial.read() to retrieve the Serial data, which I assume will all be broken down into bytes, so I need to then convert it into a HEX formate, right?
----- Update -----
I now know that I need to break down my color variable into a char-message. I'm guessing I can do something like this then, for example: And then on the other side (Arduino), I need to rebuild the message, right?
if(mousePressed == true){
//Red
myPort.write('2');
myPort.write('5');
myPort.write('5');
myPort.write(',');
//Green
myPort.write('0');
myPort.write('3');
myPort.write('0');
myPort.write(',');
//Blue
myPort.write('0');
myPort.write('0');
myPort.write('0');
myPort.write('\n');
}