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) {} }
DebounceInterrupts.h@1:ffacad1b455a, 2014-02-18 (annotated)
- Committer:
- kandangath
- Date:
- Tue Feb 18 01:07:31 2014 +0000
- Revision:
- 1:ffacad1b455a
- Parent:
- 0:ca5a0fee9f52
- Child:
- 2:a50151994483
Comment cleanup
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kandangath | 0:ca5a0fee9f52 | 1 | |
kandangath | 0:ca5a0fee9f52 | 2 | /** |
kandangath | 1:ffacad1b455a | 3 | * Debounces an InterruptIn |
kandangath | 0:ca5a0fee9f52 | 4 | */ |
kandangath | 0:ca5a0fee9f52 | 5 | |
kandangath | 0:ca5a0fee9f52 | 6 | #ifndef DEBOUNCE_INTERRUPTS_H |
kandangath | 0:ca5a0fee9f52 | 7 | #define DEBOUNCE_INTERRUPTS_H |
kandangath | 0:ca5a0fee9f52 | 8 | |
kandangath | 0:ca5a0fee9f52 | 9 | #include <stdint.h> |
kandangath | 0:ca5a0fee9f52 | 10 | #include "mbed.h" |
kandangath | 0:ca5a0fee9f52 | 11 | |
kandangath | 0:ca5a0fee9f52 | 12 | class DebounceInterrupts { |
kandangath | 0:ca5a0fee9f52 | 13 | private: |
kandangath | 0:ca5a0fee9f52 | 14 | unsigned int fDebounce_us; |
kandangath | 0:ca5a0fee9f52 | 15 | void (*fCallback)(void); |
kandangath | 0:ca5a0fee9f52 | 16 | void onInterrupt(void); |
kandangath | 0:ca5a0fee9f52 | 17 | public: |
kandangath | 0:ca5a0fee9f52 | 18 | /** Setup debounce for an InterruptIn. |
kandangath | 0:ca5a0fee9f52 | 19 | * fptr: pointer to function to be called when debounced Interrupt fires |
kandangath | 0:ca5a0fee9f52 | 20 | * interrupt: InterruptIn to monitor |
kandangath | 0:ca5a0fee9f52 | 21 | * rise: true:rise, false: fall |
kandangath | 0:ca5a0fee9f52 | 22 | * debounce_ms: milliseconds to wait for a stable input |
kandangath | 0:ca5a0fee9f52 | 23 | */ |
kandangath | 0:ca5a0fee9f52 | 24 | DebounceInterrupts(void (*fptr)(void), InterruptIn *interrupt, const bool& rise=true, const uint32_t& debounce_ms=10); |
kandangath | 0:ca5a0fee9f52 | 25 | ~DebounceInterrupts(); |
kandangath | 0:ca5a0fee9f52 | 26 | }; |
kandangath | 0:ca5a0fee9f52 | 27 | #endif |