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

Dependencies:   mbed

Revision:
0:28ab61836d38
--- /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