You will use the the sketch to switch on different primary colours of the Tri-colour LED in order to produce various combinations.
Software Discovery: setColour, analogWrite, Libraries
Other Discovery: Colour Mixing, Tri-Colour LED
Qty Part
1 Tri-Colour LED
3 Resistor [150Ω]
Software Discovery: setColour, analogWrite, Libraries
Other Discovery: Colour Mixing, Tri-Colour LED
Qty Part
1 Tri-Colour LED
3 Resistor [150Ω]
Lets get Coding!
int redPin = 11; // declare red pin of RGB-LED to pin 11
int greenPin = 10; // declare green pin of RGB-LED to pin 10
int bluePin = 9; // declare blue pin of RGB-LED to pin 9
void setup()
{
pinMode(redPin, OUTPUT); // pin 11 as output (ie. red light of RGB-LED)
pinMode(greenPin, OUTPUT); // pin 10 as output (ie. green light of RGB-LED)
pinMode(bluePin, OUTPUT); // pin 9 as output (ie. blue light of RGB-LED)
}
void loop()
{
setColor(255, 0, 0); // red light
delay (1000);
setColor(0, 255, 0); // green light
delay (1000);
setColor(0, 0, 255); // blue light
delay (1000);
}
void setColor(int red, int green, int blue) // creating the "setColor" command
{
analogWrite(redPin, red); // read the anlog value entered by user for redness
analogWrite(greenPin, green); // read the anlog value entered by user for greenness
analogWrite(bluePin, blue); // read the anlog value entered by user for blueness
}
int redPin = 11; // declare red pin of RGB-LED to pin 11
int greenPin = 10; // declare green pin of RGB-LED to pin 10
int bluePin = 9; // declare blue pin of RGB-LED to pin 9
void setup()
{
pinMode(redPin, OUTPUT); // pin 11 as output (ie. red light of RGB-LED)
pinMode(greenPin, OUTPUT); // pin 10 as output (ie. green light of RGB-LED)
pinMode(bluePin, OUTPUT); // pin 9 as output (ie. blue light of RGB-LED)
}
void loop()
{
setColor(255, 0, 0); // red light
delay (1000);
setColor(0, 255, 0); // green light
delay (1000);
setColor(0, 0, 255); // blue light
delay (1000);
}
void setColor(int red, int green, int blue) // creating the "setColor" command
{
analogWrite(redPin, red); // read the anlog value entered by user for redness
analogWrite(greenPin, green); // read the anlog value entered by user for greenness
analogWrite(bluePin, blue); // read the anlog value entered by user for blueness
}