SpringBoard
/
SB_OSthread
thread example
main.cpp@0:d8bfcd01100d, 2018-07-12 (annotated)
- Committer:
- kaushalpkk
- Date:
- Thu Jul 12 17:32:07 2018 +0000
- Revision:
- 0:d8bfcd01100d
commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kaushalpkk | 0:d8bfcd01100d | 1 | #include "mbed.h" |
kaushalpkk | 0:d8bfcd01100d | 2 | |
kaushalpkk | 0:d8bfcd01100d | 3 | DigitalOut led1(LED1); |
kaushalpkk | 0:d8bfcd01100d | 4 | DigitalOut led2(LED2); |
kaushalpkk | 0:d8bfcd01100d | 5 | Thread thread; |
kaushalpkk | 0:d8bfcd01100d | 6 | |
kaushalpkk | 0:d8bfcd01100d | 7 | void led2_thread() { |
kaushalpkk | 0:d8bfcd01100d | 8 | while (true) { |
kaushalpkk | 0:d8bfcd01100d | 9 | led2 = !led2; |
kaushalpkk | 0:d8bfcd01100d | 10 | wait(1); |
kaushalpkk | 0:d8bfcd01100d | 11 | } |
kaushalpkk | 0:d8bfcd01100d | 12 | } |
kaushalpkk | 0:d8bfcd01100d | 13 | void led1_thread() { |
kaushalpkk | 0:d8bfcd01100d | 14 | while (true) { |
kaushalpkk | 0:d8bfcd01100d | 15 | led1 = !led1; |
kaushalpkk | 0:d8bfcd01100d | 16 | wait(1); |
kaushalpkk | 0:d8bfcd01100d | 17 | } |
kaushalpkk | 0:d8bfcd01100d | 18 | } |
kaushalpkk | 0:d8bfcd01100d | 19 | |
kaushalpkk | 0:d8bfcd01100d | 20 | int main() { |
kaushalpkk | 0:d8bfcd01100d | 21 | thread.start(led2_thread); |
kaushalpkk | 0:d8bfcd01100d | 22 | thread.start(led1_thread); |
kaushalpkk | 0:d8bfcd01100d | 23 | |
kaushalpkk | 0:d8bfcd01100d | 24 | |
kaushalpkk | 0:d8bfcd01100d | 25 | while (true) { |
kaushalpkk | 0:d8bfcd01100d | 26 | led1 = !led1; |
kaushalpkk | 0:d8bfcd01100d | 27 | wait(0.5); |
kaushalpkk | 0:d8bfcd01100d | 28 | } |
kaushalpkk | 0:d8bfcd01100d | 29 | } |
kaushalpkk | 0:d8bfcd01100d | 30 | |
kaushalpkk | 0:d8bfcd01100d | 31 |