Debounce InterruptIn

Dependents:   led_sigfox Allumag_lampe_sigfox Case_study_02_Turnstile B18_MP3_PLAYER ... more

Revision:
14:da09706b92f5
Parent:
13:09b53a088a9c
Child:
17:96a51b236ba0
--- a/DebouncedInterrupt.cpp	Tue Feb 18 16:51:44 2014 +0000
+++ b/DebouncedInterrupt.cpp	Tue Feb 18 17:26:42 2014 +0000
@@ -8,10 +8,13 @@
 DebouncedInterrupt::DebouncedInterrupt(PinName pin)
 {
     _in = new InterruptIn(pin);
+    _din = new DigitalIn(pin);
 }
 
 DebouncedInterrupt::~DebouncedInterrupt()
 {
+    delete _in;
+    delete _din;
 }
 
 void DebouncedInterrupt::attach(void (*fptr)(void), 
@@ -51,7 +54,9 @@
 {
     _last_bounce_count = _bounce_count;
     _bounce_count = 0;
-    fCallback();
+    if(_din) {
+        fCallback();
+    }
 }
 
 void DebouncedInterrupt::_onInterrupt()