Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SoftSerial MAX14690 Buffer
Fork of rtos_threading_with_callback by
main.cpp@0:d4b2a035ffe3, 2017-01-12 (annotated)
- Committer:
- mab5449
- Date:
- Thu Jan 12 23:54:51 2017 +0000
- Revision:
- 0:d4b2a035ffe3
- Child:
- 2:bf699e054b34
Initiala commit. Simple RTOS threading example in mbed 5.3 using the Callback API
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mab5449 | 0:d4b2a035ffe3 | 1 | #include "mbed.h" |
mab5449 | 0:d4b2a035ffe3 | 2 | |
mab5449 | 0:d4b2a035ffe3 | 3 | Thread thread; |
mab5449 | 0:d4b2a035ffe3 | 4 | DigitalOut led1(LED1); |
mab5449 | 0:d4b2a035ffe3 | 5 | volatile bool running = true; |
mab5449 | 0:d4b2a035ffe3 | 6 | |
mab5449 | 0:d4b2a035ffe3 | 7 | // Blink function toggles the led in a long running loop |
mab5449 | 0:d4b2a035ffe3 | 8 | void blink(DigitalOut *led) { |
mab5449 | 0:d4b2a035ffe3 | 9 | while (running) { |
mab5449 | 0:d4b2a035ffe3 | 10 | *led = !*led; |
mab5449 | 0:d4b2a035ffe3 | 11 | wait(1); |
mab5449 | 0:d4b2a035ffe3 | 12 | } |
mab5449 | 0:d4b2a035ffe3 | 13 | } |
mab5449 | 0:d4b2a035ffe3 | 14 | |
mab5449 | 0:d4b2a035ffe3 | 15 | // Spawns a thread to run blink for 5 seconds |
mab5449 | 0:d4b2a035ffe3 | 16 | int main() { |
mab5449 | 0:d4b2a035ffe3 | 17 | thread.start(callback(blink, &led1)); |
mab5449 | 0:d4b2a035ffe3 | 18 | wait(5); |
mab5449 | 0:d4b2a035ffe3 | 19 | running = false; |
mab5449 | 0:d4b2a035ffe3 | 20 | thread.join(); |
mab5449 | 0:d4b2a035ffe3 | 21 | } |