Challenge Name: Multi Coloured
Name: Kyle Chan
Credit: I reference the code of newinnovators.ca
Difficulty Level: 3
Time to Complete: 5 minutes
Hint: The colour changes faster
Challenge description: The RGB LED switches between different colours on it's own
Answer:
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 = 50;
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);
}
}
}
}
No comments:
Post a Comment