Oliver Ainhirn
/
83_Thread_Signal
Signal mit mehrere LEDs
main.cpp@0:4ab541d4cb3b, 2019-03-21 (annotated)
- Committer:
- corsa1600
- Date:
- Thu Mar 21 18:49:53 2019 +0000
- Revision:
- 0:4ab541d4cb3b
Signal
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
corsa1600 | 0:4ab541d4cb3b | 1 | #include "mbed.h" |
corsa1600 | 0:4ab541d4cb3b | 2 | |
corsa1600 | 0:4ab541d4cb3b | 3 | Thread thread; |
corsa1600 | 0:4ab541d4cb3b | 4 | Thread thread2; |
corsa1600 | 0:4ab541d4cb3b | 5 | DigitalOut led(LED1); |
corsa1600 | 0:4ab541d4cb3b | 6 | DigitalOut led2(LED2); |
corsa1600 | 0:4ab541d4cb3b | 7 | DigitalOut led3(LED3); |
corsa1600 | 0:4ab541d4cb3b | 8 | |
corsa1600 | 0:4ab541d4cb3b | 9 | void led_thread() { |
corsa1600 | 0:4ab541d4cb3b | 10 | while (true) { |
corsa1600 | 0:4ab541d4cb3b | 11 | // Signal flags that are reported as event are automatically cleared. |
corsa1600 | 0:4ab541d4cb3b | 12 | Thread::signal_wait(0x1); |
corsa1600 | 0:4ab541d4cb3b | 13 | led = !led; |
corsa1600 | 0:4ab541d4cb3b | 14 | Thread::signal_wait(0x2); |
corsa1600 | 0:4ab541d4cb3b | 15 | led3 = !led3; |
corsa1600 | 0:4ab541d4cb3b | 16 | } |
corsa1600 | 0:4ab541d4cb3b | 17 | } |
corsa1600 | 0:4ab541d4cb3b | 18 | |
corsa1600 | 0:4ab541d4cb3b | 19 | void led_thread2() { |
corsa1600 | 0:4ab541d4cb3b | 20 | while (true) { |
corsa1600 | 0:4ab541d4cb3b | 21 | // Signal flags that are reported as event are automatically cleared. |
corsa1600 | 0:4ab541d4cb3b | 22 | Thread::signal_wait(0x2); |
corsa1600 | 0:4ab541d4cb3b | 23 | led2 = !led2; |
corsa1600 | 0:4ab541d4cb3b | 24 | } |
corsa1600 | 0:4ab541d4cb3b | 25 | } |
corsa1600 | 0:4ab541d4cb3b | 26 | int main (void) { |
corsa1600 | 0:4ab541d4cb3b | 27 | thread.start(callback(led_thread)); |
corsa1600 | 0:4ab541d4cb3b | 28 | thread2.start(callback(led_thread2)); |
corsa1600 | 0:4ab541d4cb3b | 29 | |
corsa1600 | 0:4ab541d4cb3b | 30 | while (true) { |
corsa1600 | 0:4ab541d4cb3b | 31 | wait(1); |
corsa1600 | 0:4ab541d4cb3b | 32 | thread.signal_set(0x1); |
corsa1600 | 0:4ab541d4cb3b | 33 | wait(1); |
corsa1600 | 0:4ab541d4cb3b | 34 | thread.signal_set(0x2); |
corsa1600 | 0:4ab541d4cb3b | 35 | wait(1); |
corsa1600 | 0:4ab541d4cb3b | 36 | thread2.signal_set(0x2); |
corsa1600 | 0:4ab541d4cb3b | 37 | } |
corsa1600 | 0:4ab541d4cb3b | 38 | |
corsa1600 | 0:4ab541d4cb3b | 39 | |
corsa1600 | 0:4ab541d4cb3b | 40 | } |