Sending multiple bytes FROM Processing TO Arduino.

Greetings, I'm trying to establish a serial communication between Processing and Arduino in order to control an RGB LED strip. My computer will use Processing to process Audio and then send RGB values to the Arduino in a form of multiple bytes. You might ask why I couldn't find anything on the Internet. I did, but most of the examples show how to send multiple bytes FROM Arduino TO Processing but not many show how to send multiple bytes FROM Processing TO Arduino.

Any Ideas?
Thank you!

Any Ideas?

Yes, It's done EXACTLY the same way. Use an array or multiple calls to Serial::write().

The Arduino code in this demo shows how to receive multiple bytes and the Python code shows how to send them. I guess the Processing code would be similar in principle to the Python code.

If you want to send binary data then this demo may be useful.

...R

PaulS:
Yes, It's done EXACTLY the same way. Use an array or multiple calls to Serial::write().

Ok, so this is what I came up with. All I have to do in Processing is send first a '0' as a byte and then three bytes with the RGB values ranging from 0-254. The Arduino then applies the values to the LED strip using PWM.

Arduino Code:

int redLed = 11; 
int greenLed = 10; 
int blueLed = 9; 

byte redValue;
byte greenValue;
byte blueValue;

byte byteCount;

void setup() {
  Serial.begin(115200);
}
 
void loop() {
  if (Serial.available() > 0) {
    byte inByte = Serial.read();
    if (inByte == '0') {
      byteCount = 0;
    }
    if (byteCount == 1) {
      redValue = inByte;
    }
    if (byteCount == 2) {
      greenValue = inByte;
    }
    if (byteCount == 3) {
      blueValue = inByte;
    }
    byteCount ++;
  }
  
  analogWrite(redLed, redValue);
  analogWrite(greenLed, greenValue);
  analogWrite(blueLed, blueValue);
}

Processing Code:

import processing.serial.*;

Serial myPort;  
int val;        

void setup() {
  size(500, 500);
  String portName = Serial.list()[3];
  myPort = new Serial(this, portName, 115200);
}

void draw() {
  background(255);
  if (mouseOverRect() == true) {  
    fill(0);                   
    myPort.write('0');
    myPort.write(254);
  } 
  else {                        
    fill(255);                       
    myPort.write('0');
    myPort.write(1);
    myPort.write(254); 
    
  }
  rect(50, 50, 400, 400);         
}

boolean mouseOverRect() { // Test if mouse is over square
  return ((mouseX >= 50) && (mouseX <= 450) && (mouseY >= 50) && (mouseY <= 450));
}

EDIT: Fixed Processing code, both sketches now work fine.