int buttonPin = 2;
int LED = 13;
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void setup()
{
pinMode(buttonPin, INPUT);
pinMode(LED,OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(buttonPin) != lastButtonState)
{
lastDebounceTime = millis(); // reset the debouncing timer
}
if ((millis() - lastDebounceTime) > debounceDelay)
{
if (digitalRead(buttonPin) != buttonState)
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
digitalWrite(LED,HIGH);
Serial.println("Press & Led ON ");
}
}
}
}