RTOS timer example - This program was borrowed from the book 'ARM-Based microcontroller projects using MBED' written by Dogan Ibrahim, Newsnes (an imprint of Elsevier) 2019. ISBN: 978-0-08-102969-5.
main.cpp@0:dd52dcc80425, 2022-04-10 (annotated)
- Committer:
- cspista
- Date:
- Sun Apr 10 12:15:08 2022 +0000
- Revision:
- 0:dd52dcc80425
Final version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| cspista | 0:dd52dcc80425 | 1 | |
| cspista | 0:dd52dcc80425 | 2 | /* RTOS timer example |
| cspista | 0:dd52dcc80425 | 3 | * This program was borrowed from the book |
| cspista | 0:dd52dcc80425 | 4 | * 'ARM-Based microcontroller projects using MBED' |
| cspista | 0:dd52dcc80425 | 5 | * written by Dogan Ibrahim |
| cspista | 0:dd52dcc80425 | 6 | * Newsnes (an imprint of Elsevier) 2019. ISBN: 978-0-08-102969-5 |
| cspista | 0:dd52dcc80425 | 7 | * |
| cspista | 0:dd52dcc80425 | 8 | * https://www.sciencedirect.com/book/9780081029695/arm-based-microcontroller-projects-using-mbed |
| cspista | 0:dd52dcc80425 | 9 | */ |
| cspista | 0:dd52dcc80425 | 10 | |
| cspista | 0:dd52dcc80425 | 11 | #include "mbed.h" |
| cspista | 0:dd52dcc80425 | 12 | #include "rtos.h" |
| cspista | 0:dd52dcc80425 | 13 | DigitalOut led(LED1); |
| cspista | 0:dd52dcc80425 | 14 | |
| cspista | 0:dd52dcc80425 | 15 | void Flash() { |
| cspista | 0:dd52dcc80425 | 16 | led = !led; // Flash the LED |
| cspista | 0:dd52dcc80425 | 17 | } |
| cspista | 0:dd52dcc80425 | 18 | |
| cspista | 0:dd52dcc80425 | 19 | int main() { |
| cspista | 0:dd52dcc80425 | 20 | led = 1; |
| cspista | 0:dd52dcc80425 | 21 | RtosTimer timer(Flash); // Create a timer |
| cspista | 0:dd52dcc80425 | 22 | timer.start(500); // Start the timer |
| cspista | 0:dd52dcc80425 | 23 | Thread::wait(5000); // Wait 5 seconds |
| cspista | 0:dd52dcc80425 | 24 | timer.stop(); // Stop the timer |
| cspista | 0:dd52dcc80425 | 25 | |
| cspista | 0:dd52dcc80425 | 26 | Thread::wait(osWaitForever); // Wait forever |
| cspista | 0:dd52dcc80425 | 27 | } |
| cspista | 0:dd52dcc80425 | 28 |