Created
February 8, 2021 18:44
-
-
Save giripriyadarshan/ca45ca8060c671b5dc1fa3de005a7b53 to your computer and use it in GitHub Desktop.
Arduino_Button_Debounce_for_interrupts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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