multipress example

Dependencies:   mbed

Revision:
0:5a93e74b5fdf
diff -r 000000000000 -r 5a93e74b5fdf main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jul 12 17:29:35 2018 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+
+Timeout flipper;
+DigitalOut led1(LED1);
+DigitalOut led2(LED4);
+InterruptIn button(p14);
+
+int count =0;
+
+void flip()
+{
+    if(count == 1) {
+        printf("single press\n");
+    } else if(count == 2) {
+    printf("double press\n");
+    } else {
+        printf("multi press\n");
+    }
+    count = 0;
+}
+
+void press()
+{
+    printf(">\n");
+    flipper.attach(&flip, 0.5);
+    count++;
+}
+
+int main(){
+    printf("Hello world\n");
+    button.rise(&press);
+
+    // spin in a main loop. flipper will interrupt it to call flip
+    while(1) {
+        led1 = !led1;
+        wait(4);
+    }
+}