GR_Peach_Abhinav_Rahul
/
test_thread
Testing thread in mbed.
main.cpp@0:adb256c0dfa9, 2016-12-03 (annotated)
- Committer:
- akverma
- Date:
- Sat Dec 03 07:25:30 2016 +0000
- Revision:
- 0:adb256c0dfa9
Basic thread implementation using RTOS.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akverma | 0:adb256c0dfa9 | 1 | #include "mbed.h" |
akverma | 0:adb256c0dfa9 | 2 | #include "rtos.h" |
akverma | 0:adb256c0dfa9 | 3 | |
akverma | 0:adb256c0dfa9 | 4 | DigitalOut led1(LED1); |
akverma | 0:adb256c0dfa9 | 5 | DigitalOut led2(LED2); |
akverma | 0:adb256c0dfa9 | 6 | |
akverma | 0:adb256c0dfa9 | 7 | void led2_thread(void const *args) { |
akverma | 0:adb256c0dfa9 | 8 | int i=0; |
akverma | 0:adb256c0dfa9 | 9 | while (i<4) { |
akverma | 0:adb256c0dfa9 | 10 | led2 = !led2; |
akverma | 0:adb256c0dfa9 | 11 | Thread::wait(1000); |
akverma | 0:adb256c0dfa9 | 12 | i++; |
akverma | 0:adb256c0dfa9 | 13 | } |
akverma | 0:adb256c0dfa9 | 14 | } |
akverma | 0:adb256c0dfa9 | 15 | |
akverma | 0:adb256c0dfa9 | 16 | int main() { |
akverma | 0:adb256c0dfa9 | 17 | led1 = 1; |
akverma | 0:adb256c0dfa9 | 18 | led2 = 1; |
akverma | 0:adb256c0dfa9 | 19 | uint8_t data[3] = {0x47, 0x32, 0xA7}; |
akverma | 0:adb256c0dfa9 | 20 | Thread thread(led2_thread); |
akverma | 0:adb256c0dfa9 | 21 | |
akverma | 0:adb256c0dfa9 | 22 | while (true) { |
akverma | 0:adb256c0dfa9 | 23 | led1 = !led1; |
akverma | 0:adb256c0dfa9 | 24 | Thread::wait(500); |
akverma | 0:adb256c0dfa9 | 25 | } |
akverma | 0:adb256c0dfa9 | 26 | } |