Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Microwave_MBED MicrowaveSimulation_LPC1768 RTOS_Alarm_Clock USB_Project_Host ... more
DebouncedInterrupt.h
00001 00002 /** A replacement for InterruptIn that debounces the interrupt 00003 * Anil Kandangath 00004 * 00005 * @code 00006 * 00007 * #include "DebouncedInterrupt.h" 00008 * 00009 * DebouncedInterrupt up_button(p15); 00010 * 00011 * void onUp() 00012 * { 00013 * // Do Something 00014 * } 00015 * 00016 * int main() 00017 * { 00018 * up_button.attach(&onUp, 100); 00019 * while(1) { 00020 * ... 00021 * } 00022 * } 00023 * @endcode 00024 */ 00025 00026 #ifndef DEBOUNCED_INTERRUPT_H 00027 #define DEBOUNCED_INTERRUPT_H 00028 00029 #include <stdint.h> 00030 #include "mbed.h" 00031 00032 class DebouncedInterrupt { 00033 private: 00034 unsigned int _debounce_us; 00035 InterruptIn *_in; 00036 DigitalIn *_din; 00037 00038 // Diagnostics 00039 volatile unsigned int _bounce_count; 00040 volatile unsigned int _last_bounce_count; 00041 00042 void (*fCallback)(void); 00043 void _onInterrupt(void); 00044 void _callback(void); 00045 public: 00046 DebouncedInterrupt(PinName pin); 00047 ~DebouncedInterrupt(); 00048 00049 // Start monitoring the interupt and attach a callback 00050 void attach(void (*fptr)(void), const uint32_t& debounce_ms=10); 00051 00052 // Stop monitoring the interrupt 00053 void reset(); 00054 00055 00056 /* 00057 * Get number of bounces 00058 * @return: bounce count 00059 */ 00060 unsigned int get_bounce(); 00061 }; 00062 #endif
Generated on Sun Jul 17 2022 20:34:59 by
1.7.2