Solution to the blocking task - do not expect this to work well however!
Fork of Task330_blocking by
main.cpp@6:2050203fd22b, 2019-09-18 (annotated)
- Committer:
- noutram
- Date:
- Wed Sep 18 10:49:18 2019 +0000
- Revision:
- 6:2050203fd22b
- Parent:
- 5:a9a9d3b7f62a
2019
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noutram | 0:397b84c74d17 | 1 | #include "mbed.h" |
noutram | 0:397b84c74d17 | 2 | #define N 1000000 |
noutram | 0:397b84c74d17 | 3 | #define RELEASED 0 |
noutram | 0:397b84c74d17 | 4 | #define PRESSED 1 |
noutram | 6:2050203fd22b | 5 | #include "demo-self-test.hpp" |
noutram | 6:2050203fd22b | 6 | |
noutram | 0:397b84c74d17 | 7 | |
noutram | 0:397b84c74d17 | 8 | //Hardware objects |
noutram | 0:397b84c74d17 | 9 | DigitalOut red_led(PE_15); //CountUp is in its critical section |
noutram | 0:397b84c74d17 | 10 | DigitalOut yellow_led(PB_10); //CountDown is in its critical section |
noutram | 0:397b84c74d17 | 11 | DigitalOut green_led(PB_11); //counter != 0 |
noutram | 0:397b84c74d17 | 12 | DigitalOut onboardLED(LED1); |
noutram | 0:397b84c74d17 | 13 | |
noutram | 0:397b84c74d17 | 14 | DigitalIn button(USER_BUTTON); |
noutram | 0:397b84c74d17 | 15 | DigitalIn sw1(PE_12); |
noutram | 0:397b84c74d17 | 16 | DigitalIn sw2(PE_14); |
noutram | 0:397b84c74d17 | 17 | |
noutram | 2:ca251bdda621 | 18 | //The code below is hugely flawed and is only to |
noutram | 2:ca251bdda621 | 19 | //illustrate the problem of blocking hardware |
noutram | 0:397b84c74d17 | 20 | int main() { |
noutram | 0:397b84c74d17 | 21 | |
noutram | 6:2050203fd22b | 22 | //Power On Self Test (POST) |
noutram | 6:2050203fd22b | 23 | POST(); |
noutram | 2:ca251bdda621 | 24 | |
noutram | 0:397b84c74d17 | 25 | //Now loop forever |
noutram | 0:397b84c74d17 | 26 | while(1) { |
noutram | 3:a39db8aa11e8 | 27 | |
noutram | 3:a39db8aa11e8 | 28 | while (sw1 == RELEASED) {}; |
noutram | 3:a39db8aa11e8 | 29 | wait(0.2); |
noutram | 3:a39db8aa11e8 | 30 | while (sw1 == PRESSED) {}; |
noutram | 3:a39db8aa11e8 | 31 | red_led = !red_led; |
noutram | 3:a39db8aa11e8 | 32 | wait(0.2); |
noutram | 2:ca251bdda621 | 33 | |
noutram | 3:a39db8aa11e8 | 34 | while (sw2 == RELEASED) {}; |
noutram | 3:a39db8aa11e8 | 35 | wait(0.2); |
noutram | 3:a39db8aa11e8 | 36 | while (sw2 == PRESSED) {}; |
noutram | 3:a39db8aa11e8 | 37 | green_led = !green_led; |
noutram | 3:a39db8aa11e8 | 38 | wait(0.2); |
noutram | 3:a39db8aa11e8 | 39 | |
noutram | 2:ca251bdda621 | 40 | //Flash the yellow |
noutram | 2:ca251bdda621 | 41 | yellow_led = !yellow_led; |
noutram | 2:ca251bdda621 | 42 | wait(0.5); |
noutram | 0:397b84c74d17 | 43 | }; |
noutram | 0:397b84c74d17 | 44 | } |