| A tri colour LED. There is a single GND pin, and three +5V pins, one each for RED, GREEN and BLUE. There are 3 separate bulbs inside this one glass outer case. |
|
There are 3 coloured LEDs within the bulb, coloured Red, Green and Blue. Put a varying voltage through each, and you get a mixture of the colours.
|
Wired up. Pins 10, 8 and 7 are used as +5V outputs through resistors to the appropriate LED RGB input. The LED then returns to GND. eg Arduino Pin 10 -> breadboard -> resistor -> TriColorLED_RED -> TriColorLED GND -> Arduino GND |
|
This is the code that I used. Originally written to control 3 separate LEDs as a 'traffic light', the code can be reused to make the tri-colour LED light up. This is using the digital outputs to give maximum brightness; we will use the analog outputs afterwards, to write out varying values to control the intensity of each colour.
int ledDelay = 200; // delay in between changes
int redPin = 10;
int yellowPin = 8;
int greenPin = 7;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
// turn the red light on
digitalWrite(redPin, HIGH);
delay(ledDelay); // wait
digitalWrite(yellowPin, HIGH); // turn on yellow
delay(200); // wait
digitalWrite(greenPin, HIGH); // turn green on
digitalWrite(redPin, LOW); // turn red off
digitalWrite(yellowPin, LOW); // turn yellow off
delay(ledDelay); // wait
digitalWrite(yellowPin, HIGH); // turn yellow on
digitalWrite(greenPin, LOW); // turn green off
delay(200); // wait
digitalWrite(yellowPin, LOW); // turn yellow off
// now our loop repeats
}
|