int dialValue; //introduce variable
void setup() {
Serial.begin(9600); //begin serial communication
pinMode(A0,INPUT); //A0 is an input
pinMode(7, OUTPUT); //pin 7 is an output
}
void loop() {
dialValue=analogRead(A0); //read from pin A0 and store it to dialValue
Serial.println(dialValue); //print that value
if(dialValue>500) //check if value is greater than 500
{
digitalWrite(7,HIGH); //if so send high signal to pin 7
}
else
{
digitalWrite(7,LOW); //if not turn it to low signal
}
}
Challenge: Add two more lights from two other pins, so that now you have 3 in total. You can use the RGB LED if you want as well. Write code that reads the dial and as the dialValue increases turn more lights on. When the dialValue is low turn all of the lights off, as it increases turn one on, then another, then another as the value increases. You'll need to pick your thresholds. Go back to if/else if/else if you've forgotten how to create multiple conditions.