multipress to change pwm blinky

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
kaushalpkk
Date:
Thu Jul 12 17:31:29 2018 +0000
Commit message:
commit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jul 12 17:31:29 2018 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+
+Timeout flipper;
+DigitalOut led1(LED1);
+PwmOut led2(LED4);
+InterruptIn button(p14);
+
+int count =0;
+
+void flip()
+{
+    if(count == 1) {
+        printf("single press\n");
+        led2 = 0;
+    } else if(count == 2) {
+        printf("double press\n");
+        led2 = 0.3;
+    } else {
+        printf("multi press\n");
+        led2 = 1;
+    }
+    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);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jul 12 17:31:29 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file