Oliver Ainhirn
/
81_Thread_03
version3 mit 4 Leds
main.cpp@2:7b860e46bf67, 2019-03-14 (annotated)
- Committer:
- corsa1600
- Date:
- Thu Mar 14 18:44:06 2019 +0000
- Revision:
- 2:7b860e46bf67
- Parent:
- 1:f17f1b284f68
Version mit 4 Leds
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
corsa1600 | 0:300fb6f45ac9 | 1 | #include "mbed.h" |
corsa1600 | 0:300fb6f45ac9 | 2 | |
corsa1600 | 0:300fb6f45ac9 | 3 | DigitalOut led1(LED1); |
corsa1600 | 0:300fb6f45ac9 | 4 | DigitalOut led2(LED2); |
corsa1600 | 2:7b860e46bf67 | 5 | DigitalOut led3(LED3); |
corsa1600 | 2:7b860e46bf67 | 6 | DigitalOut led4(LED4); |
corsa1600 | 2:7b860e46bf67 | 7 | Thread thread(osPriorityHigh); |
corsa1600 | 2:7b860e46bf67 | 8 | Thread thread3(osPriorityNormal); |
corsa1600 | 2:7b860e46bf67 | 9 | Thread thread4(osPriorityLow); |
corsa1600 | 0:300fb6f45ac9 | 10 | |
corsa1600 | 1:f17f1b284f68 | 11 | void led2_thread() |
corsa1600 | 1:f17f1b284f68 | 12 | { |
corsa1600 | 1:f17f1b284f68 | 13 | double x, y =1.99, z=0.99; |
corsa1600 | 0:300fb6f45ac9 | 14 | while (true) { |
corsa1600 | 0:300fb6f45ac9 | 15 | led2 = !led2; |
corsa1600 | 1:f17f1b284f68 | 16 | wait(0.5); |
corsa1600 | 1:f17f1b284f68 | 17 | |
corsa1600 | 1:f17f1b284f68 | 18 | for (int j=0; j<100; j++) |
corsa1600 | 2:7b860e46bf67 | 19 | for (int i=0; i<100; i++) |
corsa1600 | 2:7b860e46bf67 | 20 | x = y*z+x; |
corsa1600 | 2:7b860e46bf67 | 21 | |
corsa1600 | 2:7b860e46bf67 | 22 | } |
corsa1600 | 2:7b860e46bf67 | 23 | } |
corsa1600 | 2:7b860e46bf67 | 24 | void led3_thread() |
corsa1600 | 2:7b860e46bf67 | 25 | { |
corsa1600 | 2:7b860e46bf67 | 26 | double x, y =1.99, z=0.99; |
corsa1600 | 2:7b860e46bf67 | 27 | while (true) { |
corsa1600 | 2:7b860e46bf67 | 28 | led3 = !led3; |
corsa1600 | 2:7b860e46bf67 | 29 | wait(0.5); |
corsa1600 | 2:7b860e46bf67 | 30 | |
corsa1600 | 2:7b860e46bf67 | 31 | for (int j=0; j<100; j++) |
corsa1600 | 2:7b860e46bf67 | 32 | for (int i=0; i<100; i++) |
corsa1600 | 2:7b860e46bf67 | 33 | x = y*z+x; |
corsa1600 | 2:7b860e46bf67 | 34 | |
corsa1600 | 2:7b860e46bf67 | 35 | } |
corsa1600 | 2:7b860e46bf67 | 36 | } |
corsa1600 | 2:7b860e46bf67 | 37 | |
corsa1600 | 2:7b860e46bf67 | 38 | void led4_thread() |
corsa1600 | 2:7b860e46bf67 | 39 | { |
corsa1600 | 2:7b860e46bf67 | 40 | double x, y =1.99, z=0.99; |
corsa1600 | 2:7b860e46bf67 | 41 | while (true) { |
corsa1600 | 2:7b860e46bf67 | 42 | led4 = !led4; |
corsa1600 | 2:7b860e46bf67 | 43 | wait(0.5); |
corsa1600 | 2:7b860e46bf67 | 44 | |
corsa1600 | 2:7b860e46bf67 | 45 | for (int j=0; j<100; j++) |
corsa1600 | 2:7b860e46bf67 | 46 | for (int i=0; i<100; i++) |
corsa1600 | 1:f17f1b284f68 | 47 | x = y*z+x; |
corsa1600 | 1:f17f1b284f68 | 48 | |
corsa1600 | 0:300fb6f45ac9 | 49 | } |
corsa1600 | 0:300fb6f45ac9 | 50 | } |
corsa1600 | 0:300fb6f45ac9 | 51 | |
corsa1600 | 0:300fb6f45ac9 | 52 | int main() { |
corsa1600 | 0:300fb6f45ac9 | 53 | thread.start(led2_thread); |
corsa1600 | 2:7b860e46bf67 | 54 | thread3.start(led3_thread); |
corsa1600 | 2:7b860e46bf67 | 55 | thread4.start(led4_thread); |
corsa1600 | 2:7b860e46bf67 | 56 | osThreadSetPriority(osThreadGetId(), osPriorityBelowNormal); |
corsa1600 | 1:f17f1b284f68 | 57 | double x, y=1.99, z=0.99; |
corsa1600 | 0:300fb6f45ac9 | 58 | while (true) { |
corsa1600 | 0:300fb6f45ac9 | 59 | led1 = !led1; |
corsa1600 | 1:f17f1b284f68 | 60 | wait(0.25); |
corsa1600 | 1:f17f1b284f68 | 61 | for (int j=0; j<200; j++) |
corsa1600 | 2:7b860e46bf67 | 62 | for (int i=0; i<200; i++) |
corsa1600 | 1:f17f1b284f68 | 63 | x = y*z+x; |
corsa1600 | 1:f17f1b284f68 | 64 | |
corsa1600 | 0:300fb6f45ac9 | 65 | } |
corsa1600 | 0:300fb6f45ac9 | 66 | } |