Basic example showing the Thread API
mbed 2 and mbed OS 5
This is an mbed 2 example. mbed OS 5 has integrated the mbed library with mbed-rtos. For an mbed-os example, please see:
Import programrtos_basic
basic rtos example
main.cpp@10:dc33cd3f4eb9, 2017-01-12 (annotated)
- Committer:
- mab5449
- Date:
- Thu Jan 12 23:35:40 2017 +0000
- Revision:
- 10:dc33cd3f4eb9
- Parent:
- 9:dd58814e2dcf
- Child:
- 11:0309bef74ba8
Wait times updated;
Who changed what in which revision?
User | Revision | Line number | New 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; |
mab5449 | 10:dc33cd3f4eb9 | 10 | wait(1); |
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; |
mab5449 | 10:dc33cd3f4eb9 | 19 | wait(0.5); |
emilmont | 1:491820ee784d | 20 | } |
emilmont | 1:491820ee784d | 21 | } |