Multicolor LED
Set up your breadboard similar to as shown and use the 220 resistors for your board.
Getting the colors on (Blinking)
Use the same code that you used to get your regular LEDs on and off and see if you can get them to turn on the Multi color LED's colors. You may have to change the pin numbers used in your code. If you have trouble, you can start with this code below.
Now that you got one light on, go ahead and change your code to try and change colors or get two colors on at once.
Set Colors your own color
This code is used to set up your led to be multiple colors and brightness at once.
You change the numbers in the "setColor(255, 0, 0);" part to change what colors your LED makes.
You change the numbers in the "setColor(255, 0, 0);" part to change what colors your LED makes.
Getting the colors to switch
Now that you have gotten the code to work, try adding the other colors to digitalWrites to get the colors to switch.
You add this to the loop just like you added delays and more digitalWrites to your blink code.
You add this to the loop just like you added delays and more digitalWrites to your blink code.
Once you get it to work, change the values in the set color part to numbers between 0-255 and see what happens.
Getting the colors to fade
See if you can get your RGB LED to fade in and out with this code. You can copy and paste this below code to save time. Comments are there to help you understand it, but those aren't needed for the computer.
#define BLUE 3 //We are defining the different colors
#define GREEN 5 //to the different pins
#define RED 6 // change the numbers to what you have plugged in
#define delay 10 // fading time between colors
void setup(){
pinMode(RED, OUTPUT); // these three lines setup the light's pins to be outputs
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
digitalWrite(RED, LOW); // these three lines initialize the lights to start off
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
}
int redValue; // define variables
int greenValue;
int blueValue;
void loop(){
redValue = 255; // this code starts with red on, choose between 0 and 255 to change the colors.
greenValue = 0;
blueValue = 0;
for(int i = 0; i < 255; i += 1) { // fades out red bring green full when i=255
redValue -= 1; // makes red dimmer by one each delay time
greenValue += 1; // makes green brighter by one each delay time
analogWrite(RED, redValue);
analogWrite(GREEN, greenValue);
delay(delay);
}
for(int i = 0; i < 255; i += 1) { // fades out green bring blue full when i=255
greenValue -= 1;
blueValue += 1;
analogWrite(GREEN, greenValue);
analogWrite(BLUE, blueValue);
delay(delay);
}
for(int i = 0; i < 255; i += 1) { // fades out blue bring red full when i=255
blueValue -= 1;
redValue += 1;
analogWrite(BLUE, blueValue);
analogWrite(RED, redValue);
delay(delay);
} // then it will loop forever
}
#define BLUE 3 //We are defining the different colors
#define GREEN 5 //to the different pins
#define RED 6 // change the numbers to what you have plugged in
#define delay 10 // fading time between colors
void setup(){
pinMode(RED, OUTPUT); // these three lines setup the light's pins to be outputs
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
digitalWrite(RED, LOW); // these three lines initialize the lights to start off
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
}
int redValue; // define variables
int greenValue;
int blueValue;
void loop(){
redValue = 255; // this code starts with red on, choose between 0 and 255 to change the colors.
greenValue = 0;
blueValue = 0;
for(int i = 0; i < 255; i += 1) { // fades out red bring green full when i=255
redValue -= 1; // makes red dimmer by one each delay time
greenValue += 1; // makes green brighter by one each delay time
analogWrite(RED, redValue);
analogWrite(GREEN, greenValue);
delay(delay);
}
for(int i = 0; i < 255; i += 1) { // fades out green bring blue full when i=255
greenValue -= 1;
blueValue += 1;
analogWrite(GREEN, greenValue);
analogWrite(BLUE, blueValue);
delay(delay);
}
for(int i = 0; i < 255; i += 1) { // fades out blue bring red full when i=255
blueValue -= 1;
redValue += 1;
analogWrite(BLUE, blueValue);
analogWrite(RED, redValue);
delay(delay);
} // then it will loop forever
}