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.
Revision 2:2a43e5048e22, committed 2019-02-23
- Comitter:
 - marcozecchini
 - Date:
 - Sat Feb 23 11:52:22 2019 +0000
 - Parent:
 - 1:2e6e3436fc61
 - Commit message:
 - Final commit
 
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file | 
--- a/main.cpp	Wed Feb 20 15:56:57 2019 +0000
+++ b/main.cpp	Sat Feb 23 11:52:22 2019 +0000
@@ -2,25 +2,58 @@
  /*
   * Button with interrupt example
   */
-  
+
 InterruptIn mybutton(USER_BUTTON);
 DigitalOut myled(LED1);
+Timer t;
  
 float delay = 5.0; // 1 sec
  
 void pressed()
 {
+    t.stop();
+    printf("You pressed after %f seconds\n", t.read());
     if (delay == 5.0)
         delay = 0.2; // 200 ms
     else
         delay = 5.0; // 1 sec
+    t.reset();
+    t.start();
 }
  
 int main()
-{
+{   
+    t.start();
     mybutton.fall(&pressed);
     while (1) {
-        myled = !myled;
+        myled = !myled; //toggle the led
         wait(delay);
     }
 }
+
+/*
+ * Timeout version
+ */
+/* 
+  
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+Timeout timeout;
+ 
+void flip()
+{
+    led2 = !led2;
+}
+ 
+int main()
+{   
+    led2 = 1;
+    timeout.attach(&flip, 2.0); // setup flipper to call flip after 2 seconds
+ 
+    // spin in a main loop. flipper will interrupt it to call flip
+    while(1) {
+        led1 = !led1;
+        wait(0.2);
+    }
+}
+*/
\ No newline at end of file