Matthaeus Vorraber
/
app-InterruptIn-Ticker-Timeout
TimerLed
main.cpp@1:4f4f8acfae13, 2019-12-16 (annotated)
- Committer:
- happy_alien
- Date:
- Mon Dec 16 17:18:22 2019 +0000
- Revision:
- 1:4f4f8acfae13
- Parent:
- 0:28ab61836d38
timerLed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fpucher | 0:28ab61836d38 | 1 | #include "mbed.h" |
fpucher | 0:28ab61836d38 | 2 | #define BUTTON1 p14 // push joystick pin |
fpucher | 0:28ab61836d38 | 3 | //#define BUTTON1 A1 // NUCLEO Taster A1 |
fpucher | 0:28ab61836d38 | 4 | |
fpucher | 0:28ab61836d38 | 5 | DigitalOut led1(LED1); |
fpucher | 0:28ab61836d38 | 6 | DigitalOut led2(LED2); // NUCLEO D2 |
fpucher | 0:28ab61836d38 | 7 | DigitalOut led3(LED3); // NUCLEO D3 |
happy_alien | 1:4f4f8acfae13 | 8 | DigitalOut led4(LED4); |
fpucher | 0:28ab61836d38 | 9 | |
happy_alien | 1:4f4f8acfae13 | 10 | Ticker t1,t3; |
fpucher | 0:28ab61836d38 | 11 | Timeout t2; |
fpucher | 0:28ab61836d38 | 12 | InterruptIn btn(BUTTON1); |
fpucher | 0:28ab61836d38 | 13 | |
fpucher | 0:28ab61836d38 | 14 | void blink_led1() { |
fpucher | 0:28ab61836d38 | 15 | printf("Ticker fired\n"); |
fpucher | 0:28ab61836d38 | 16 | led1 = !led1; |
fpucher | 0:28ab61836d38 | 17 | } |
happy_alien | 1:4f4f8acfae13 | 18 | void blink_led4() |
happy_alien | 1:4f4f8acfae13 | 19 | { |
happy_alien | 1:4f4f8acfae13 | 20 | led4=!led4; |
happy_alien | 1:4f4f8acfae13 | 21 | |
happy_alien | 1:4f4f8acfae13 | 22 | |
happy_alien | 1:4f4f8acfae13 | 23 | |
happy_alien | 1:4f4f8acfae13 | 24 | } |
fpucher | 0:28ab61836d38 | 25 | void toggle_led2() { |
fpucher | 0:28ab61836d38 | 26 | printf("BUTTON1 fall invoked\n"); |
fpucher | 0:28ab61836d38 | 27 | led2 = !led2; |
fpucher | 0:28ab61836d38 | 28 | } |
fpucher | 0:28ab61836d38 | 29 | |
fpucher | 0:28ab61836d38 | 30 | void turn_led3_on() { |
fpucher | 0:28ab61836d38 | 31 | printf("Timeout fired\n"); |
fpucher | 0:28ab61836d38 | 32 | led3 = 1; |
fpucher | 0:28ab61836d38 | 33 | } |
fpucher | 0:28ab61836d38 | 34 | |
fpucher | 0:28ab61836d38 | 35 | int main() { |
fpucher | 0:28ab61836d38 | 36 | printf("Hello world!\n"); |
fpucher | 0:28ab61836d38 | 37 | printf("LED1 will blink every second, LED3 will toggle after 2.5 seconds, LED2 can be toggled through BUTTON1.\n"); |
fpucher | 0:28ab61836d38 | 38 | printf("-----------------------------------\n\n"); |
fpucher | 0:28ab61836d38 | 39 | |
fpucher | 0:28ab61836d38 | 40 | t1.attach(callback(&blink_led1), 1.0f); |
fpucher | 0:28ab61836d38 | 41 | t2.attach(callback(&turn_led3_on), 2.5f); |
happy_alien | 1:4f4f8acfae13 | 42 | t3.attach(callback(&blink_led4),5.0f); |
fpucher | 0:28ab61836d38 | 43 | btn.fall(callback(&toggle_led2)); |
fpucher | 0:28ab61836d38 | 44 | |
fpucher | 0:28ab61836d38 | 45 | while(1) {} |
fpucher | 0:28ab61836d38 | 46 | // wait_ms(osWaitForever); |
fpucher | 0:28ab61836d38 | 47 | } |