const int VL = 4; // the number of the swich pin, VL stands for logic voltage
const int PR = 2; // the number of the LED pin, PR stands for red probe
const int PG = 3; // the number of the LED pin, PG stand for green probe
const int VP = A0; // select the input pin for the potentiometer
// variables will change:
// int SwitchState = 0; // give a name for the switch state variable
int PotValue = 0; // variable to store the value coming from the sensor
//declares the inputs and outputs of the circuit
void setup() {
pinMode(A0, INPUT);
// pinMode(VL, INPUT);
pinMode(PR, OUTPUT);
pinMode(PG, OUTPUT);
}
// your code written here keeps running until eternity
void loop() {
//reads from the switch to determine which LED should be on
// SwitchState = digitalRead(VL);
//reads from the pot pin and assign it to the PotValue
PotValue = analogRead(VP);
//When the pot reading is less than 250, both the red and green LEDS are turned off
if (PotValue < 250)
{
digitalWrite(PR, 0);
digitalWrite(PG, 1);
}
//When the pot reading is less than 500 and greater than 250, the red LED is turned off and the green LED is turned on
else if (PotValue < 500)
{
digitalWrite(PR, 0);
digitalWrite(PG, 0);
}
//When the pot reading is less than 750 and greater than 500, both the red and green LEDS are turned on
else if (PotValue < 750)
{
digitalWrite(PR, 1);
digitalWrite(PG, 0);
}
//When the pot reading is greater than 750, the red LED is turned on and the green LED is turned off
else
{
digitalWrite(PR, 1);
digitalWrite(PG, 1);
}
}