2 leds blinking with 2 different threads
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 00004 DigitalOut led2(LED2); 00005 DigitalOut led3(LED3); 00006 00007 // Blink function toggles the led in a long running loop 00008 void blink_led(DigitalOut *led) { 00009 *led = !*led; 00010 wait(1); 00011 *led = !*led; 00012 } 00013 00014 00015 00016 // Spawns a thread to run blink for 5 seconds 00017 int main() { 00018 while(1) { 00019 Thread thread1; 00020 Thread thread2; 00021 thread1.start(callback(blink_led, &led2)); 00022 thread1.join(); 00023 thread2.start(callback(blink_led, &led3)); 00024 thread2.join(); 00025 } 00026 }
Generated on Fri Sep 30 2022 11:46:41 by
1.7.2