Code to make the 3 Colour LED change between red, green, blue, white. Put resistors between the pin inputs and the led pins. If you use the right resistors then the colours will be more precise.

 

// Use Resistors on each pin (anything above 180 ohm I think)

int ledpinr = 9;
int ledping = 10;
int ledpinb = 11;
int red = 0;
int blue = 0;
int green = 0;
 
void setup() {
  //Nothing to setup
}
 
void changeColor(int red, int green, int blue){
  //Set PWM on pins 9 10 and 11
  analogWrite(ledpinr, red);
  analogWrite(ledping, green);
  analogWrite(ledpinb, blue);
  delay(500);
}
 
void loop() {
  //Red
  changeColor(255, 0, 0);
 
  //Green
  changeColor(0, 255, 0);
 
  //Blue
  changeColor(0, 0, 255);
 
  //White
  changeColor(255, 255, 255);
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.