Timer

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
roosalyn
Date:
Wed Sep 09 07:45:57 2015 +0000
Commit message:
Timer

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	Wed Sep 09 07:45:57 2015 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"
+
+DigitalIn button(PTA4);
+DigitalOut blue(LED3);
+Timer timer;
+int nBlinky = 1;
+int buttonState = 1;
+
+void blinkRed(int nblinks) {
+    for (int i=0; i < nblinks; i++) {
+        blue.write(0);
+        wait(0.2);
+        blue.write(1);
+        wait(0.2);
+    }
+}
+
+bool buttonPressed(){
+
+    if (button.read() == 0 && buttonState == 1){
+        buttonState = 0;
+        return true;
+    }
+    if (button.read() == 1 && buttonState == 0){
+        buttonState = 1;
+    }
+    return false;
+}
+
+void count() {
+    if (buttonPressed()) {
+        nBlinky++;
+    }
+}
+
+int main()
+{
+    blue = 1;
+
+    while (true) {
+        if (buttonPressed()) {
+            timer.reset();
+            timer.start();
+            nBlinky = 1;
+            while (timer.read_ms() <= 2000) {
+                count();
+            }
+            blinkRed(nBlinky);
+        }
+
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Sep 09 07:45:57 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/ba1f97679dad
\ No newline at end of file