Multiple thread example based on mbed-os

Fork of rtos_basic by mbed official

This is a very basic of RTOS thread example using mbed-os. In this example, LED1 and LED2 are toggling with the interval of 500ms and 1000ms respectively. LED1 blinking is running in the while in main, meantime LED2 blinking is running in a thread. This shows how task(s) can operate independently.

Committer:
tsungta
Date:
Fri Mar 31 02:47:46 2017 +0000
Revision:
13:196d7844af97
Parent:
12:7f932ecea853
remove mbed_app.json since mbed-os lib is updated to mbed-os-5.4.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:491820ee784d 1 #include "mbed.h"
emilmont 1:491820ee784d 2
emilmont 1:491820ee784d 3 DigitalOut led1(LED1);
emilmont 1:491820ee784d 4 DigitalOut led2(LED2);
geky 7:8d9919175929 5 Thread thread;
emilmont 1:491820ee784d 6
geky 7:8d9919175929 7 void led2_thread() {
emilmont 1:491820ee784d 8 while (true) {
emilmont 1:491820ee784d 9 led2 = !led2;
mbed_official 11:0309bef74ba8 10 Thread::wait(1000);
emilmont 1:491820ee784d 11 }
emilmont 1:491820ee784d 12 }
emilmont 1:491820ee784d 13
emilmont 1:491820ee784d 14 int main() {
geky 7:8d9919175929 15 thread.start(led2_thread);
emilmont 1:491820ee784d 16
emilmont 1:491820ee784d 17 while (true) {
emilmont 1:491820ee784d 18 led1 = !led1;
mbed_official 11:0309bef74ba8 19 Thread::wait(500);
emilmont 1:491820ee784d 20 }
emilmont 1:491820ee784d 21 }