![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
gg
Fork of Workshop-1-Example-3 by
main.cpp@0:04fa7fb0681e, 2016-09-26 (annotated)
- Committer:
- sarahmarshy
- Date:
- Mon Sep 26 16:14:45 2016 +0000
- Revision:
- 0:04fa7fb0681e
Initial commit. Threaded blinky.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sarahmarshy | 0:04fa7fb0681e | 1 | #include "mbed.h" |
sarahmarshy | 0:04fa7fb0681e | 2 | #include "rtos.h" |
sarahmarshy | 0:04fa7fb0681e | 3 | |
sarahmarshy | 0:04fa7fb0681e | 4 | DigitalOut led1(LED1); |
sarahmarshy | 0:04fa7fb0681e | 5 | DigitalOut led2(LED2); |
sarahmarshy | 0:04fa7fb0681e | 6 | |
sarahmarshy | 0:04fa7fb0681e | 7 | void led2_thread(void const *args) { |
sarahmarshy | 0:04fa7fb0681e | 8 | while (true) { |
sarahmarshy | 0:04fa7fb0681e | 9 | led2 = !led2; |
sarahmarshy | 0:04fa7fb0681e | 10 | Thread::wait(1000); |
sarahmarshy | 0:04fa7fb0681e | 11 | } |
sarahmarshy | 0:04fa7fb0681e | 12 | } |
sarahmarshy | 0:04fa7fb0681e | 13 | |
sarahmarshy | 0:04fa7fb0681e | 14 | int main() { |
sarahmarshy | 0:04fa7fb0681e | 15 | //Create a thread to execute the function led2_thread |
sarahmarshy | 0:04fa7fb0681e | 16 | Thread thread(led2_thread); |
sarahmarshy | 0:04fa7fb0681e | 17 | //led2_thread is executing concurrently with main at this point |
sarahmarshy | 0:04fa7fb0681e | 18 | |
sarahmarshy | 0:04fa7fb0681e | 19 | while (true) { |
sarahmarshy | 0:04fa7fb0681e | 20 | led1 = !led1; |
sarahmarshy | 0:04fa7fb0681e | 21 | Thread::wait(500); |
sarahmarshy | 0:04fa7fb0681e | 22 | } |
sarahmarshy | 0:04fa7fb0681e | 23 | } |