
2 leds blinking with 2 different threads
Revision 0:05b174e27260, committed 2018-11-15
- Comitter:
- iandil
- Date:
- Thu Nov 15 13:56:51 2018 +0000
- Commit message:
- Finished threads synchronization
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed-os.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 05b174e27260 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Nov 15 13:56:51 2018 +0000 @@ -0,0 +1,26 @@ +#include "mbed.h" + + +DigitalOut led2(LED2); +DigitalOut led3(LED3); + +// Blink function toggles the led in a long running loop +void blink_led(DigitalOut *led) { + *led = !*led; + wait(1); + *led = !*led; +} + + + +// Spawns a thread to run blink for 5 seconds +int main() { + while(1) { + Thread thread1; + Thread thread2; + thread1.start(callback(blink_led, &led2)); + thread1.join(); + thread2.start(callback(blink_led, &led3)); + thread2.join(); + } +} \ No newline at end of file
diff -r 000000000000 -r 05b174e27260 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Thu Nov 15 13:56:51 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/armmbed/mbed-os/#bf6f2c3c6434a6de9eb9511feffa5948b3d1f20f