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(random(0,255),random(0,255),random(0,255)); //Call RGBcolor function // which will send a random number between 0_255 //toeach color pin 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) }