Purpose
To make a RGB LED change colours
Equipment
-RGB LED
-330ohm resistor
-3 wires(any colour)
Program Details
Arduino
Time
10 mins
Results
LEDs were in wrong way
Photo/Video proof
None right now
Program
const int RED_LED_PIN = 9; -Creates a constant variable for Red led to pin 9
const int GREEN_LED_PIN = 10; -Creates a constant variable for Green led to pin 10
const int BLUE_LED_PIN = 11; -Creates a constant variable for Blue led to pin 11
int redIntensity = 0; -How much light would generate for the red led
int greenIntensity = 0; -How much light would generate for the green led
int blueIntensity = 0; --How much light would generate for the blue led
const int DISPLAY_TIME = 100; - -Creates a constant variable for time
void setup()- there is no void setup
{
}
void loop() -Starting the void loop()
{-Start of void loop()
for (greenIntensity = 0; greenIntensity <= 255; greenIntensity+=5)-The value of green increases from 0-255 increasing by 5 each loop.
{- Start of for loop
redIntensity = 255-greenIntensity;- red led will adjust to green
analogWrite(GREEN_LED_PIN, greenIntensity);-Power is given to green led
analogWrite(RED_LED_PIN, redIntensity);--Power is given to red led
delay(DISPLAY_TIME); -pauses the program for a bit
}-end of for loop
for (blueIntensity = 0; blueIntensity <= 255; blueIntensity+=5)-The value of blue increases from 0-255 increasing by 5 each loop.
{-Start of for loop
greenIntensity = 255-blueIntensity;-green led will adjust to blue
analogWrite(BLUE_LED_PIN, blueIntensity);-Power is given to blue led
analogWrite(GREEN_LED_PIN, greenIntensity);-Power is given to green led
delay(DISPLAY_TIME); -pauses the program for a bit
}-End of for loop
for (redIntensity = 0; redIntensity <= 255; redIntensity+=5)The value of red increases from 0-255 increasing by 5 each loop.
{-Start of for loop
blueIntensity = 255-redIntensity; -blue led will adjust to red
analogWrite(RED_LED_PIN, redIntensity);-Power is given to red led
analogWrite(BLUE_LED_PIN, blueIntensity);-Power is given to blue led
delay(DISPLAY_TIME); -pauses the program for a bit
}-End of for loop
}-End of program
Program Modifications:
none
Helpful Tips:
Don't put LEDs in the wrong way
References:
Aron Graca
Kyle Chan