#define button_pin 34
#define led_pin 5
#define debouncetime 20
int laststate = LOW;
int lastflickerablestate = LOW;
int currentstate;
unsigned long lastdebouncetime = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led_pin, OUTPUT);
pinMode(button_pin, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
currentstate = digitalRead(button_pin);
if (currentstate != lastflickerablestate){
lastdebouncetime = millis();
lastflickerablestate = currentstate;
}
if ((millis() - lastdebouncetime) > debouncetime){
if (laststate == HIGH && currentstate == LOW)
digitalWrite(led_pin, LOW);
else if (laststate == LOW && currentstate == HIGH)
digitalWrite(led_pin, HIGH);
laststate = currentstate;
}
}