// ------------
// ECE 210 - Lab 4
// ------------

/*-------------

  Author: Giri Venkataramanan
  This code is used in ECE 210 in Practicum 4.
  The code demonstrates reading analog signals and sending output of bit level logic signals
  after doing some logic comparison operations
  Pin A0 is used to read potentiometer signal input
  Pin D2 (red LED) and Pin D11 (green LED) are used to write signal outputs
  Pin D2 and D11 indicate the size of the voltage measured at A0 following a logic as programmed

  -------------*/

// constants won't change. They're used here to set pin numbers:
// const int VL = 4;     // the number of the swich pin, VL stands for logic voltage
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);
  }
}
$abcdeabcde151015202530354045505560fghijfghij