Push and hold button to start timer. Release button to print time that the button was held for.

Dependencies:   mbed

Fork of Timer_HelloWorld by mbed official

Revision:
1:272adee7c4ac
Parent:
0:27e1de20d3cb
Child:
2:1e6dc5131b1b
diff -r 27e1de20d3cb -r 272adee7c4ac main.cpp
--- a/main.cpp	Wed Feb 13 17:28:57 2013 +0000
+++ b/main.cpp	Tue Jan 07 00:24:41 2014 +0000
@@ -1,10 +1,22 @@
 #include "mbed.h"
  
+DigitalIn button1(PTC3); //button for KL46Z
 Timer t;
+
+bool pushed = false;
  
 int main() {
-    t.start();
-    printf("Hello World!\n");
-    t.stop();
-    printf("The time taken was %f seconds\n", t.read());
-}
+    while(true) {
+        if(!button1 && !pushed) {
+            t.start();
+            printf("Timer Started\r\n");
+            pushed = true;
+        }
+        else if(button1 && pushed) {
+            t.stop();
+            printf("The time taken was %f seconds\r\n", t.read());
+            t.reset();
+            pushed = false;
+        }
+    }
+}
\ No newline at end of file