String firstValue, secondValue, thirdValue, myString, inString=""; int r,g,b,inChar; void setup() { pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); // Open serial communications and wait for port to open: Serial.begin(9600); } void loop() { if (Serial.available()>0) { inChar = Serial.read(); changeValues(inChar); } } void changeValues(int X) { // convert the incoming byte to a char and add it to the string: inString += (char)X; int commaIndex = inString.indexOf('-'); // Search for the next comma just after the first int secondCommaIndex = inString.indexOf('-', commaIndex + 1); firstValue = inString.substring(0, commaIndex); secondValue = inString.substring(commaIndex + 1, secondCommaIndex); thirdValue = inString.substring(secondCommaIndex + 1); // To the end of the string r = firstValue.toInt(); g = secondValue.toInt(); b = thirdValue.toInt(); analogWrite(9,r); analogWrite(10,g); analogWrite(11,b); }