Christian Weiß / Mbed 2 deprecated TimerInt

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Wizo
Date:
Thu Nov 15 18:05:48 2018 +0000
Commit message:
TimerInt

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 Nov 15 18:05:48 2018 +0000
@@ -0,0 +1,43 @@
+// switch blue LEDs LED1 .. LED4 with external interrupt functionality
+/* 
+3 classes
+Timeout - Call a function after a specified delay
+Ticker - Repeatedly call a function
+Timer - Create, start, stop and read a timer
+*/
+
+#include "mbed.h"
+
+Timeout toFlipper;
+DigitalOut doLed1(LED1);
+DigitalOut doLed2(LED2);
+Ticker tickBlinker; 
+DigitalOut doLed3(LED3);
+Timer tMyTimer;
+Serial pc(USBTX, USBRX); // tx, rx
+
+// functions 
+void flip() {
+    doLed1 = !doLed1;
+}
+
+void blink() {
+    doLed3 = !doLed3;
+}
+ 
+int main() {
+    doLed2 = 1;
+    toFlipper.attach(&flip, 2.0);     // setup flipper to call flip after 2 seconds
+    tickBlinker.attach(&blink, 0.5);    // setup blinker to call blink avery 500 msec
+ 
+    // spin in a main loop. flipper will interrupt it to call flip
+    while(1) {
+        tMyTimer.reset();
+        tMyTimer.start();
+        pc.printf("Hello Timer-World!   ");
+        doLed1 = !doLed1;
+        wait(1.0);
+        tMyTimer.stop();
+        pc.printf("The time taken was %f seconds\r", tMyTimer.read());    
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Nov 15 18:05:48 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/5aab5a7997ee
\ No newline at end of file