Skip to content

Instantly share code, notes, and snippets.

@giripriyadarshan
Created February 8, 2021 18:44
Show Gist options
  • Save giripriyadarshan/ca45ca8060c671b5dc1fa3de005a7b53 to your computer and use it in GitHub Desktop.
Save giripriyadarshan/ca45ca8060c671b5dc1fa3de005a7b53 to your computer and use it in GitHub Desktop.
Arduino_Button_Debounce_for_interrupts
const byte led_pin = LED_BUILTIN;
const byte interrupt_pin = 2;
volatile byte state = LOW;
unsigned long interrupt_time = millis();
const unsigned long delay_time = 50; // Delay for every push button may vary
void setup() {
pinMode(led_pin, OUTPUT);
pinMode(interrupt_pin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interrupt_pin), blynk, LOW);
}
void loop() {
digitalWrite(led_pin, state);
}
void blynk() {
if ((millis() - interrupt_time) > delay_time) {
// Recommend to not to change the position of this line
interrupt_time = millis();
// Interrupt function lines
state = !state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment