This lab will teach you how to make one RBG LED to change colours.
Equipment:
-1 RGB LED (common anode)
-3 330 ohm resistors
-1 wire (red)
-1 wire (black)
-4 wires (any colour)
-1 Arduino UNO
-1 breadboard
-1 USB cable
Program Details:
-Download Arduino here
Time to Program and Complete:
-Approximately 30 min
Results:
-There were some spelling and spacing errors, but after they were fixed the Arduino worked completely fine
Photo/Video:
Program:
const int RED_LED_PIN = 9;
const int GREEN_LED_PIN = 10;
const int BLUE_LED_PIN = 11;
int redIntensity = 0;
int greenIntensity = 0;
int blueIntensity = 0;
const int DISPLAY_TIME = 100;
void setup()
{
}
void loop()
{
for (greenIntensity = 0; greenIntensity <= 255; greenIntensity +=5)
{
redIntensity = 255-greenIntensity;
analogWrite(GREEN_LED_PIN, greenIntensity);
analogWrite(RED_LED_PIN, redIntensity);
delay(DISPLAY_TIME);
}
for (blueIntensity = 0; blueIntensity <= 255; blueIntensity +=5)
{
greenIntensity = 255-blueIntensity;
analogWrite(BLUE_LED_PIN, blueIntensity);
analogWrite(GREEN_LED_PIN, greenIntensity);
delay(DISPLAY_TIME);
}
for(redIntensity = 0; redIntensity <= 255; redIntensity +=5)
{
blueIntensity = 255-redIntensity;
analogWrite (RED_LED_PIN, redIntensity);
analogWrite (BLUE_LED_PIN, blueIntensity);
delay(DISPLAY_TIME);
}
}
Program Modifications:
-There were none
Helpful Tips:
-Check spacing/spelling
References:
-Arduino website: arduino.cc
-New Innovators: Lab 5
No comments:
Post a Comment