-
1Run a Program
int greenLed = 2;
int yellowLed = 3;
int redLed = 4;int analogValue = 0; // analogValue variable is where we will be storing the value that comes from the analog input//
float voltage = 0;
int ledDelay = 1000; //ledDelay is how long you want the LEDs to remain on before switching off////set up all our LED pins as outputs//
void setup()
{
pinMode(greenLed, OUTPUT);
pinMode(yellowLed,OUTPUT);
pinMode(redLed,OUTPUT);
}// Read the analog pin //
void loop()
{
analogValue = analogRead(A0);
voltage = 0.0048*analogValue;
//Compare calculated voltage with defined voltage values//
if( voltage >= 1.6 )
digitalWrite(greenLed, HIGH);
else if (voltage > 1.2 && voltage < 1.6)
digitalWrite(yellowLed, HIGH);
else if( voltage <= 1.2)digitalwrite(redled, HIGH);
delay(leddelay);
digitalWrite(redLed, LOW);
digitalWrite(yellowLed, LOW);
digitalWrite(greenLed, LOW);
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.