You could simplify the protocol. Simply send 3 rgb values or nothing. 3 values of zero is off.
int redpin = 3;
int greenpin = 5;
int bluepin = 6;
void setLeds(int r, int g, int b)
{
analogWrite(redpin, r);
analogWrite(greenpin, g);
analogWrite(bluepin, b);
}
void setup() {
pinMode(redpin, OUTPUT); //set the pins as output
pinMode(greenpin, OUTPUT);
pinMode(bluepin, OUTPUT);
setLeds(0, 0, 0); //turn the pins off
Serial.begin(9600); //begin the serial monitor at 9600 baud
Serial.print("Hello"); //say Hello, be polite!
}
void dumpValues(int r, int g, int b)
{
//for debugging:
Serial.print(" ");
Serial.print(r);
Serial.print(" ");
Serial.print(g);
Serial.print(" ");
Serial.print(b);
Serial.print(" ");
}
int readSerial()
{
while(Serial.available() == 0);
return Serial.parseInt();
}
void loop() {
int r = readSerial();
int g = readSerial();
int b = readSerial();
setLeds(r, g, b);
dumpValues(r, g, b);
}