#define S0 2
#define Led_Gruen 11
unsigned long startwert;
bool Flag=0, S0_h;
void setup() {
// put your setup code here, to run once:
pinMode(S0, INPUT_PULLUP);
pinMode(Led_Gruen, OUTPUT);
}
void loop() {
// Eingänge einlesen und invertieren (wegen Pullup)
S0_h = !digitalRead(S0);
if(S0_h)
{
if(Flag ==0)
{
startwert=millis();
Flag=1;
}
}
else if(!S0_h)
Flag=0;
if((millis()-startwert>= 4000) and S0_h)
digitalWrite(Led_Gruen,HIGH);
else if(!S0_h)
{
digitalWrite(Led_Gruen,LOW);
startwert = millis();
}
}