Background: I'm using two buttons to control the number displayed on an LCD screen (an up button and a down button). I want to use external interrupts to determine whether the up/down button is pressed or not. I know one button press can trigger multiple interrupts and must be debounced. I went through this tutorial which discusses using a capacitor and an internal schmitt trigger for debouncing.
Problem: Now I'm trying to implement debouncing without using an internal schmitt trigger and instead using a combination of external and timer interrupts. Something like this:
External interrupt (up button press)
Disable external interrupt
Enable timer interrupt
Background: I'm using two buttons to control the number displayed on an LCD screen (an up button and a down button). I want to use external interrupts to determine whether the up/down button is pressed or not. I know one button press can trigger multiple interrupts and thus must be debounced. I went through this tutorial which discusses using a capacitor and an internal schmitt trigger for debouncing.
Problem: Now I'm trying to implement debouncing without using an internal schmitt trigger and instead using a combination of external and timer interrupts. Something like this:
External interrupt (up button press)
Disable external interrupt (up button press)
Enable timer interrupt
Rest of the code
Timer interrupt
Enable external interrupt
This way another interrupt cannot be triggered until the time set for the timer interrupt has run out and it gets triggered. I know I could use attachInterrupt and detachInterrupt to enable/disable the external interrupts. But is there an analogous code to enable/disable timer interrupts?
htp://www.gammon.com.au/switches
You don't need to disable timer interrupts. See the above link.
I'm going through your "Debouncing without delay" section. So would it be okay to have an if statement equivalent to this (from your website):
if (millis () - switchPressTime >= debounceTime)
in the code for my external interrupt? But using this method the external interrupt will still get triggered multiple times, it just wont execute the code within the interrupt multiple times.
A capacitor should be all you need, but yes, you should be able to test in the interrupt routine.
Oh actually I don't think the millis() function will work because it resets after a certain amount of days. I was hoping to run this indefinitely.
gkiverm123:
Oh actually I don't think the millis() function will work because it resets after a certain amount of days. I was hoping to run this indefinitely.
The "reset" (rollover) won't affect your timing if you implement millis() in the standard, correct way. Only, the maximum delay is limited to a certain number of days.
gkiverm123:
Oh actually I don't think the millis() function will work because it resets after a certain amount of days. I was hoping to run this indefinitely.
Not if you code it properly: Gammon Forum : Electronics : Microprocessors : millis() overflow ... a bad thing?
Your watch resets at midnight each day. Does that stop you using it indefinitely?