I have a pot that sends a voltage from 0-5 volts which I use to display data with LEDS. However the pot can rotate just past 360 deg and the voltage goes back to 0. I don't want to display 0 in this case. I set a flag OVER to check for this condition and keep 6 displayed. .
However my syntax is not correct and I can't get it right,
int analogin = A0; // input pin for the potentiometer
int LEDa = 2;
int LEDb = A3;
int LEDc = A1;
int LEDd = 11;
int LEDe = 0;
int LEDf = 4;
int LEDg = A2;
int DIM = 5;
boolean OVER;
int ATD = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(LEDa, OUTPUT);
pinMode(LEDb, OUTPUT);
pinMode(LEDc, OUTPUT);
pinMode(LEDd, OUTPUT);
pinMode(LEDe, OUTPUT);
pinMode(LEDf, OUTPUT);
pinMode(LEDg, OUTPUT);
pinMode(DIM, INPUT);
// OVER = HIGH;
}
void loop()
{
ATD = analogRead(analogin);
if ((ATD <= 190) && (OVER == LOW)) //0
{
digitalWrite(LEDa, LOW);
digitalWrite(LEDb, LOW);
digitalWrite(LEDc, LOW);
digitalWrite(LEDd, LOW);
digitalWrite(LEDe, LOW);
digitalWrite(LEDf, LOW);
digitalWrite(LEDg, HIGH);
}
else if ((ATD >= 210) && (ATD <= 260)) //1
{
digitalWrite(LEDa, HIGH);
digitalWrite(LEDb, HIGH);
digitalWrite(LEDc, HIGH);
digitalWrite(LEDd, HIGH);
digitalWrite(LEDe, LOW);
digitalWrite(LEDf, LOW);
digitalWrite(LEDg, HIGH);
}
else if ((ATD >= 340) && (ATD <= 400)) //2
{
digitalWrite(LEDa, LOW);
digitalWrite(LEDb, LOW);
digitalWrite(LEDc, HIGH);
digitalWrite(LEDd, LOW);
digitalWrite(LEDe, HIGH);
digitalWrite(LEDf, LOW);
digitalWrite(LEDg, LOW);
}
else if ((ATD >= 480) && (ATD <= 540)) //3
{
digitalWrite(LEDa, LOW);
digitalWrite(LEDb, HIGH);
digitalWrite(LEDc, HIGH);
digitalWrite(LEDd, LOW);
digitalWrite(LEDe, LOW);
digitalWrite(LEDf, LOW);
digitalWrite(LEDg, LOW);
}
else if ((ATD >= 620) && (ATD <= 675)) //4
{
digitalWrite(LEDa, HIGH);
digitalWrite(LEDb, HIGH);
digitalWrite(LEDc, LOW);
digitalWrite(LEDd, HIGH);
digitalWrite(LEDe, LOW);
digitalWrite(LEDf, LOW);
digitalWrite(LEDg, LOW);
OVER = LOW;
}
else if ((ATD >= 760) && (ATD <= 815)) //5
{
digitalWrite(LEDa, LOW);
digitalWrite(LEDb, HIGH);
digitalWrite(LEDc, LOW);
digitalWrite(LEDd, LOW);
digitalWrite(LEDe, LOW);
digitalWrite(LEDf, HIGH);
digitalWrite(LEDg, LOW);
OVER = HIGH;
}
else if ((ATD >= 900) || ((ATD <= 100) && (OVER == HIGH))) //6
{
digitalWrite(LEDa, LOW);
digitalWrite(LEDb, LOW);
digitalWrite(LEDc, LOW);
digitalWrite(LEDd, LOW);
digitalWrite(LEDe, LOW);
digitalWrite(LEDf, HIGH);
digitalWrite(LEDg, LOW);
}
else
{
digitalWrite(LEDa, HIGH);
digitalWrite(LEDb, HIGH);
digitalWrite(LEDc, HIGH);
digitalWrite(LEDd, HIGH);
digitalWrite(LEDe, HIGH);
digitalWrite(LEDf, HIGH);
digitalWrite(LEDg, HIGH);
}
}