Franz Pucher / Mbed 2 deprecated app-InterruptIn-Ticker-Timeout

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #define BUTTON1 p14     // push joystick pin
00003 //#define BUTTON1 A1    // NUCLEO Taster A1
00004  
00005 DigitalOut led1(LED1);
00006 DigitalOut led2(LED2);  // NUCLEO D2
00007 DigitalOut led3(LED3);  // NUCLEO D3
00008  
00009 Ticker t1;
00010 Timeout t2;
00011 InterruptIn btn(BUTTON1);
00012  
00013 void blink_led1() {
00014     printf("Ticker fired\n");
00015     led1 = !led1;
00016 }
00017  
00018 void toggle_led2() {
00019     printf("BUTTON1 fall invoked\n");
00020     led2 = !led2;
00021 }
00022  
00023 void turn_led3_on() {
00024     printf("Timeout fired\n");
00025     led3 = 1;
00026 }
00027  
00028 int main() {
00029     printf("Hello world!\n");
00030     printf("LED1 will blink every second, LED3 will toggle after 2.5 seconds, LED2 can be toggled through BUTTON1.\n");
00031     printf("-----------------------------------\n\n");
00032  
00033     t1.attach(callback(&blink_led1), 1.0f);
00034     t2.attach(callback(&turn_led3_on), 2.5f);
00035     btn.fall(callback(&toggle_led2));
00036  
00037     while(1) {}
00038     // wait_ms(osWaitForever);
00039 }