Author: Christina He
Credit: New Innovatos: Lab 5
Difficulty: Level 3
Time to Complete: Approximately 40 min
Challenge Description: Make the RGB LED to change colours when twisting the potentiometer.
Answer:
Code
const int red= 9;
const int green= 10;
const int blue= 11;
const int pot= A0;
const int distime= 100;
void setup()
{
pinMode(pot, INPUT);
}
void loop()
{
int a=analogRead(pot)/63.75;
if (a==4)
{
analogWrite(green,255);
delay(distime);
analogWrite(green,0);
}
else if (a==3)
{
analogWrite(blue, 255);
delay(distime);
analogWrite(blue,0);
}
else
{
analogWrite (red,255);
delay(distime);
analogWrite(red,0);
}
}
Visual Answer
No comments:
Post a Comment