int RED = 11; //Connect red color leg of RGB to PWM digital pin 11 int GREEN = 10; //Connect green color leg of RGB to PWM digital pin 10 int BLUE = 9; //Connect blue color leg of RGB to PWM digital pin 9 void setup() { RGBcolor(0,0,0); pinMode(RED, OUTPUT); // Set RED pin as an output pin pinMode(GREEN, OUTPUT); // Set GREEN pin as an output pin pinMode(BLUE, OUTPUT); // Set BLUE pin as an output pin Serial.begin(9600); } void loop() { if(Serial.available() > 0){ char Mycolor = Serial.read(); if(Mycolor == 'r'){ RGBcolor(255,0,0); } else if (Mycolor == 'g'){ RGBcolor(0,255,0); } else if (Mycolor == 'b'){ RGBcolor(0,0,255); } else if (Mycolor == 'd'){ RGBcolor(random(0,255),random(0,255),random(0,255)); } else { RGBcolor(0,0,0); } } } void RGBcolor(int Rval, int Gval, int Bval){ Rval = 255-Rval; Gval = 255-Gval; Bval = 255-Bval; analogWrite(RED,Rval); analogWrite(GREEN,Gval); analogWrite(BLUE,Bval); }