![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Ticker Code
Dependencies: mbed
Fork of Ticker_HelloWorld by
main.cpp@1:f2e353fb0e7e, 2018-02-28 (annotated)
- Committer:
- bjs9
- Date:
- Wed Feb 28 09:56:15 2018 +0000
- Revision:
- 1:f2e353fb0e7e
- Parent:
- 0:5014bf742e9b
Ticker Code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:5014bf742e9b | 1 | #include "mbed.h" |
mbed_official | 0:5014bf742e9b | 2 | |
mbed_official | 0:5014bf742e9b | 3 | Ticker flipper; |
bjs9 | 1:f2e353fb0e7e | 4 | Ticker flipper2; |
bjs9 | 1:f2e353fb0e7e | 5 | Ticker flipper3; |
bjs9 | 1:f2e353fb0e7e | 6 | Ticker flipper4; |
mbed_official | 0:5014bf742e9b | 7 | DigitalOut led1(LED1); |
mbed_official | 0:5014bf742e9b | 8 | DigitalOut led2(LED2); |
bjs9 | 1:f2e353fb0e7e | 9 | DigitalOut led3(LED3); |
bjs9 | 1:f2e353fb0e7e | 10 | DigitalOut led4(LED4); |
mbed_official | 0:5014bf742e9b | 11 | |
mbed_official | 0:5014bf742e9b | 12 | void flip() { |
bjs9 | 1:f2e353fb0e7e | 13 | led1 = !led1; |
bjs9 | 1:f2e353fb0e7e | 14 | } |
bjs9 | 1:f2e353fb0e7e | 15 | void flip2() { |
mbed_official | 0:5014bf742e9b | 16 | led2 = !led2; |
mbed_official | 0:5014bf742e9b | 17 | } |
bjs9 | 1:f2e353fb0e7e | 18 | void flip3() { |
bjs9 | 1:f2e353fb0e7e | 19 | led3 = !led3; |
bjs9 | 1:f2e353fb0e7e | 20 | } |
bjs9 | 1:f2e353fb0e7e | 21 | void flip4() { |
bjs9 | 1:f2e353fb0e7e | 22 | led4 = !led4; |
bjs9 | 1:f2e353fb0e7e | 23 | } |
mbed_official | 0:5014bf742e9b | 24 | |
mbed_official | 0:5014bf742e9b | 25 | int main() { |
bjs9 | 1:f2e353fb0e7e | 26 | led1 = 1; |
mbed_official | 0:5014bf742e9b | 27 | led2 = 1; |
bjs9 | 1:f2e353fb0e7e | 28 | led3 = 1; |
bjs9 | 1:f2e353fb0e7e | 29 | led4 = 1; |
bjs9 | 1:f2e353fb0e7e | 30 | flipper.attach(&flip, 1.0); // the address of the function to be attached (flip) and the interval (2 seconds) |
bjs9 | 1:f2e353fb0e7e | 31 | flipper2.attach(&flip2, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds) |
bjs9 | 1:f2e353fb0e7e | 32 | flipper3.attach(&flip3, 4.0); // the address of the function to be attached (flip) and the interval (2 seconds) |
bjs9 | 1:f2e353fb0e7e | 33 | flipper4.attach(&flip4, 8.0); // the address of the function to be attached (flip) and the interval (2 seconds) |
mbed_official | 0:5014bf742e9b | 34 | // spin in a main loop. flipper will interrupt it to call flip |
mbed_official | 0:5014bf742e9b | 35 | while(1) { |
mbed_official | 0:5014bf742e9b | 36 | } |
mbed_official | 0:5014bf742e9b | 37 | } |