A replacement for InterruptIn that debounces the interrupt.
Dependents: D7A_Demo-Get-started CVtoOSCConverter EE3501keypad D7A_Localisation ... more
Fork of DebouncedInterrupt by
Example code:
#include "DebouncedInterrupt.h" DebouncedInterrupt up_button(USER_BUTTON); void onUp() { // Do Something } int main() { // Will immediatly call function and ignore other interrupts until timeout up_button.attach(&onUp, IRQ_FALL, 1000, true); // Will call function only if button has been held for the specified time //up_button.attach(&onUp, IRQ_FALL, 500, false); while(1) {} }
Diff: DebouncedInterrupt.h
- Revision:
- 26:2df374d23986
- Parent:
- 25:2163ebb21aef
--- a/DebouncedInterrupt.h Wed Apr 26 11:02:18 2017 +0000 +++ b/DebouncedInterrupt.h Thu Apr 27 16:06:12 2017 +0000 @@ -56,7 +56,7 @@ volatile unsigned int _last_bounce_count; void _onInterrupt(void); - void _callback(void); + void _onCallback(void); public: DebouncedInterrupt(PinName pin); ~DebouncedInterrupt(); @@ -66,7 +66,7 @@ template<typename T, typename M> void attach(T *obj, M method, const gpio_irq_event trigger, const uint32_t debounce_ms=10, bool immediate=false) { - _fAttach.attach(callback(obj, method)); + _callback = callback(obj, method); _last_bounce_count = _bounce_count = 0; _debounce_us = 1000*debounce_ms; _trigger = trigger; @@ -96,6 +96,6 @@ unsigned int get_bounce(); protected: // https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/api/FunctionPointer.h - Callback<void()> _fAttach; + Callback<void()> _callback; }; #endif \ No newline at end of file