![](/media/cache/profiles/af7fc8485f40dc495bc626d6dbe7faf1.50x50_q85.png)
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@7:8d9919175929, 2016-11-22 (annotated)
- Committer:
- geky
- Date:
- Tue Nov 22 18:04:36 2016 +0000
- Revision:
- 7:8d9919175929
- Parent:
- 3:c92e21f305d8
- Child:
- 8:c1e1db61aee7
Update to use start function
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 | #include "rtos.h" |
emilmont | 1:491820ee784d | 3 | |
emilmont | 1:491820ee784d | 4 | DigitalOut led1(LED1); |
emilmont | 1:491820ee784d | 5 | DigitalOut led2(LED2); |
geky | 7:8d9919175929 | 6 | Thread thread; |
emilmont | 1:491820ee784d | 7 | |
geky | 7:8d9919175929 | 8 | void led2_thread() { |
emilmont | 1:491820ee784d | 9 | while (true) { |
emilmont | 1:491820ee784d | 10 | led2 = !led2; |
emilmont | 1:491820ee784d | 11 | Thread::wait(1000); |
emilmont | 1:491820ee784d | 12 | } |
emilmont | 1:491820ee784d | 13 | } |
emilmont | 1:491820ee784d | 14 | |
emilmont | 1:491820ee784d | 15 | int main() { |
geky | 7:8d9919175929 | 16 | thread.start(led2_thread); |
emilmont | 1:491820ee784d | 17 | |
emilmont | 1:491820ee784d | 18 | while (true) { |
emilmont | 1:491820ee784d | 19 | led1 = !led1; |
emilmont | 1:491820ee784d | 20 | Thread::wait(500); |
emilmont | 1:491820ee784d | 21 | } |
emilmont | 1:491820ee784d | 22 | } |