Add two threads into the IOT WIFIDemo for test_JacobShi
Dependencies: C12832 HTTPClient wifiontros wifirtos mbed
Fork of frdm_rtos by
main.cpp@0:7fd883bfe9a3, 2014-04-03 (annotated)
- Committer:
- Kojto
- Date:
- Thu Apr 03 11:51:25 2014 +0000
- Revision:
- 0:7fd883bfe9a3
- Child:
- 3:5f921ff0868d
initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 0:7fd883bfe9a3 | 1 | #include "mbed.h" |
Kojto | 0:7fd883bfe9a3 | 2 | #include "rtos.h" |
Kojto | 0:7fd883bfe9a3 | 3 | |
Kojto | 0:7fd883bfe9a3 | 4 | DigitalOut led1(LED1); |
Kojto | 0:7fd883bfe9a3 | 5 | InterruptIn sw2(SW2); |
Kojto | 0:7fd883bfe9a3 | 6 | uint32_t button_pressed; |
Kojto | 0:7fd883bfe9a3 | 7 | Thread *thread2; |
Kojto | 0:7fd883bfe9a3 | 8 | |
Kojto | 0:7fd883bfe9a3 | 9 | void sw2_press(void) |
Kojto | 0:7fd883bfe9a3 | 10 | { |
Kojto | 0:7fd883bfe9a3 | 11 | thread2->signal_set(0x1); |
Kojto | 0:7fd883bfe9a3 | 12 | } |
Kojto | 0:7fd883bfe9a3 | 13 | |
Kojto | 0:7fd883bfe9a3 | 14 | void led_thread(void const *argument) |
Kojto | 0:7fd883bfe9a3 | 15 | { |
Kojto | 0:7fd883bfe9a3 | 16 | while (true) { |
Kojto | 0:7fd883bfe9a3 | 17 | led1 = !led1; |
Kojto | 0:7fd883bfe9a3 | 18 | Thread::wait(1000); |
Kojto | 0:7fd883bfe9a3 | 19 | } |
Kojto | 0:7fd883bfe9a3 | 20 | } |
Kojto | 0:7fd883bfe9a3 | 21 | |
Kojto | 0:7fd883bfe9a3 | 22 | void button_thread(void const *argument) |
Kojto | 0:7fd883bfe9a3 | 23 | { |
Kojto | 0:7fd883bfe9a3 | 24 | while (true) { |
Kojto | 0:7fd883bfe9a3 | 25 | Thread::signal_wait(0x1); |
Kojto | 0:7fd883bfe9a3 | 26 | button_pressed++; |
Kojto | 0:7fd883bfe9a3 | 27 | } |
Kojto | 0:7fd883bfe9a3 | 28 | } |
Kojto | 0:7fd883bfe9a3 | 29 | |
Kojto | 0:7fd883bfe9a3 | 30 | int main() |
Kojto | 0:7fd883bfe9a3 | 31 | { |
Kojto | 0:7fd883bfe9a3 | 32 | Thread thread(led_thread); |
Kojto | 0:7fd883bfe9a3 | 33 | thread2 = new Thread(button_thread); |
Kojto | 0:7fd883bfe9a3 | 34 | |
Kojto | 0:7fd883bfe9a3 | 35 | button_pressed = 0; |
Kojto | 0:7fd883bfe9a3 | 36 | sw2.fall(&sw2_press); |
Kojto | 0:7fd883bfe9a3 | 37 | while (true) { |
Kojto | 0:7fd883bfe9a3 | 38 | Thread::wait(5000); |
Kojto | 0:7fd883bfe9a3 | 39 | printf("SW2 was pressed (last 5 seconds): %d \n", button_pressed); |
Kojto | 0:7fd883bfe9a3 | 40 | fflush(stdout); |
Kojto | 0:7fd883bfe9a3 | 41 | button_pressed = 0; |
Kojto | 0:7fd883bfe9a3 | 42 | } |
Kojto | 0:7fd883bfe9a3 | 43 | } |