R L / mbed-src

Fork of mbed-src by mbed official

Revision:
636:21ce76d41a4f
Parent:
212:34d62c0b2af6
--- a/common/InterruptIn.cpp	Wed Sep 30 17:00:09 2015 +0100
+++ b/common/InterruptIn.cpp	Sun Feb 21 07:27:08 2016 +0000
@@ -17,6 +17,9 @@
 
 #if DEVICE_INTERRUPTIN
 
+static int button_buf[5] = {0};
+static int inc = 0;
+
 namespace mbed {
 
 InterruptIn::InterruptIn(PinName pin) : gpio(),
@@ -76,7 +79,18 @@
 
 #ifdef MBED_OPERATORS
 InterruptIn::operator int() {
-    return read();
+    
+    button_buf[inc++] = read();
+    if (inc == 5) inc = 0;
+    if (button_buf[0] == button_buf[1] && 
+        button_buf[1] == button_buf[2] && 
+        button_buf[2] == button_buf[3] && 
+        button_buf[3] == button_buf[4]){
+    
+        return button_buf[0];
+    } else {
+        return 1;
+    }
 }
 #endif