Program from Mbed-Simulator for InterruptIn, Ticker, and Timeout

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
fpucher
Date:
Mon Dec 09 11:17:47 2019 +0000
Commit message:
First Version

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
diff -r 000000000000 -r 28ab61836d38 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 09 11:17:47 2019 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#define BUTTON1 p14     // push joystick pin
+//#define BUTTON1 A1    // NUCLEO Taster A1
+ 
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);  // NUCLEO D2
+DigitalOut led3(LED3);  // NUCLEO D3
+ 
+Ticker t1;
+Timeout t2;
+InterruptIn btn(BUTTON1);
+ 
+void blink_led1() {
+    printf("Ticker fired\n");
+    led1 = !led1;
+}
+ 
+void toggle_led2() {
+    printf("BUTTON1 fall invoked\n");
+    led2 = !led2;
+}
+ 
+void turn_led3_on() {
+    printf("Timeout fired\n");
+    led3 = 1;
+}
+ 
+int main() {
+    printf("Hello world!\n");
+    printf("LED1 will blink every second, LED3 will toggle after 2.5 seconds, LED2 can be toggled through BUTTON1.\n");
+    printf("-----------------------------------\n\n");
+ 
+    t1.attach(callback(&blink_led1), 1.0f);
+    t2.attach(callback(&turn_led3_on), 2.5f);
+    btn.fall(callback(&toggle_led2));
+ 
+    while(1) {}
+    // wait_ms(osWaitForever);
+}
\ No newline at end of file
diff -r 000000000000 -r 28ab61836d38 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Dec 09 11:17:47 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file