![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Ticker Example
Fork of Workshop-1-Example-2 by
Diff: main.cpp
- Revision:
- 1:965926ce34a0
- Parent:
- 0:41a092c2e9d3
--- a/main.cpp Mon Sep 26 16:13:44 2016 +0000 +++ b/main.cpp Fri Jan 20 11:53:01 2017 +0000 @@ -1,21 +1,42 @@ #include "mbed.h" -Ticker flipper; +Serial pc(USBTX,USBRX); + +Ticker L1,L2,L3,L4; + DigitalOut led1(LED1); DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); -void flip() { +void led_1() { + led1 = !led1; + //pc.printf("LED 1 toogled\n"); +} + +void led_2() { led2 = !led2; + //pc.printf("LED 2 toogled\n"); +} + +void led_3() { + led3 = !led3; + // pc.printf("LED 3 toogled\n"); +} + +void led_4() { + led4 = !led4; + // pc.printf("LED 4 toogled\n"); } int main() { - led2 = 1; - flipper.attach(&flip, 2.0); // call flip function every 2 seconds - + L1.attach(&led_1, ((rand()%10)+1)); + L2.attach(&led_2, ((rand()%10)+1)); // call flip function every 2 seconds + L3.attach(&led_3, ((rand()%10)+1)); + L4.attach(&led_4, ((rand()%10)+1)); // spin in a main loop. flipper will interrupt it to call flip while(1) { - led1 = !led1; - wait(0.2); - } + + } } \ No newline at end of file