Hi,
i have a poti which gives me values. If the value is over 700 a led should switch on. But after a specific time for example two secconds it should switch off. When the poti values go under 700 again and then above 700 again it should start over again (switch LED on and after 2 sec off again).
i have written a code but something is not working out how it should.
int poti = A0;
int potiwert = 0;
int LED = 3;
unsigned long startTime;
int timing = false;
unsigned long timeOut = 2000;
void setup()
{
pinMode(poti, INPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600);
}
void loop()
{
potiwert = analogRead(poti);
//Serial.println(potiwert);
if(potiwert > 700)
{
digitalWrite(LED, HIGH);
Serial.println("EIN");
startTime = millis();
timing = true;
}
else
{
digitalWrite(LED, LOW);
Serial.println("AUS1");
}
if (timing == true)
{
if(millis() - startTime > timeOut)
{
digitalWrite(LED, LOW);
Serial.println("AUS2");
timing = false;
}
}
}
Thanks for your help!