int switchPin = 8;
int LEDpin = 4;
int reading;
int switchState = LOW;
int LEDState = LOW;
unsigned long switchTime;
int lastSwitch = LOW;
int debounceTime = 50;
void setup()
{
pinMode(LEDpin, OUTPUT);
}
void loop()
{
reading = digitalRead(switchPin);
if(reading != lastSwitch)
{
switchTime = millis();
lastSwitch = reading;
}
if((millis() - switchTime) > debounceTime)
{if(reading !=switchState)
{
if (reading == HIGH && switchState == LOW) LEDState =!LEDState;
digitalWrite(LEDpin, LEDState);
switchState = reading;
}
}
}