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() { 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 } void loop() { RGBcolor(255,0,0); // Call RGBcolor function to give a RED color delay(1000); // wait for a second RGBcolor(0,255,0); // Call RGBcolor function to give a GREEN color delay(1000); RGBcolor(0,0,255);// Call RGBcolor function to give a BLUE color delay(1000); RGBcolor(0,0,0);// Call RGBcolor function to OFF the RGB delay(1000); RGBcolor(0,247,255); // Call RGBcolor function to give a Cyan color delay(1000); RGBcolor(157,13,253); // Call RGBcolor function to an unknown color :P just see it delay(1000); RGBcolor(255,240,9);// Call RGBcolor function to an unknown color :P just see it delay(1000); RGBcolor(0,0,0);// Call RGBcolor function to OFF the RG delay(1000); } void RGBcolor(int Rval, int Gval, int Bval){ //to give the desired value to each pin Rval = 255-Rval;//For common ANODE subtract the given number for RED from 255 Gval = 255-Gval;//For common ANODE subtract the given number for GREEN from 255 Bval = 255-Bval;//For common ANODE subtract the given number for BLUE from 255 analogWrite(RED,Rval); // Send modified RED color value to RED pin (PWM pin) analogWrite(GREEN,Gval);// Send modified GREEN color value to GREEN pin (PWM pin) analogWrite(BLUE,Bval);// Send modified BLUE color value to BLUE pin (PWM pin) }