University of Plymouth - Stages 1, 2 and 3 / Mbed OS Task330_blocking

Fork of Task330_blocking by University of Plymouth - Stages 1, 2 and 3

Committer:
noutram
Date:
Tue Oct 24 13:27:27 2017 +0000
Revision:
5:a9a9d3b7f62a
Parent:
4:e71c1e3bc4a6
Child:
6:2050203fd22b
for students

Who changed what in which revision?

UserRevisionLine numberNew 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 0:397b84c74d17 5
noutram 0:397b84c74d17 6 //Hardware objects
noutram 0:397b84c74d17 7 DigitalOut red_led(PE_15); //CountUp is in its critical section
noutram 0:397b84c74d17 8 DigitalOut yellow_led(PB_10); //CountDown is in its critical section
noutram 0:397b84c74d17 9 DigitalOut green_led(PB_11); //counter != 0
noutram 0:397b84c74d17 10 DigitalOut onboardLED(LED1);
noutram 0:397b84c74d17 11
noutram 0:397b84c74d17 12 DigitalIn button(USER_BUTTON);
noutram 0:397b84c74d17 13 DigitalIn sw1(PE_12);
noutram 0:397b84c74d17 14 DigitalIn sw2(PE_14);
noutram 0:397b84c74d17 15
noutram 2:ca251bdda621 16 //The code below is hugely flawed and is only to
noutram 2:ca251bdda621 17 //illustrate the problem of blocking hardware
noutram 0:397b84c74d17 18 int main() {
noutram 0:397b84c74d17 19
noutram 2:ca251bdda621 20 //Light up
noutram 2:ca251bdda621 21 red_led = 1;
noutram 0:397b84c74d17 22 yellow_led = 1;
noutram 2:ca251bdda621 23 green_led = 1;
noutram 2:ca251bdda621 24 onboardLED = 1;
noutram 2:ca251bdda621 25
noutram 0:397b84c74d17 26 //Now loop forever
noutram 0:397b84c74d17 27 while(1) {
noutram 3:a39db8aa11e8 28
noutram 3:a39db8aa11e8 29 while (sw1 == RELEASED) {};
noutram 3:a39db8aa11e8 30 wait(0.2);
noutram 3:a39db8aa11e8 31 while (sw1 == PRESSED) {};
noutram 3:a39db8aa11e8 32 red_led = !red_led;
noutram 3:a39db8aa11e8 33 wait(0.2);
noutram 2:ca251bdda621 34
noutram 3:a39db8aa11e8 35 while (sw2 == RELEASED) {};
noutram 3:a39db8aa11e8 36 wait(0.2);
noutram 3:a39db8aa11e8 37 while (sw2 == PRESSED) {};
noutram 3:a39db8aa11e8 38 green_led = !green_led;
noutram 3:a39db8aa11e8 39 wait(0.2);
noutram 3:a39db8aa11e8 40
noutram 2:ca251bdda621 41 //Flash the yellow
noutram 2:ca251bdda621 42 yellow_led = !yellow_led;
noutram 2:ca251bdda621 43 wait(0.5);
noutram 0:397b84c74d17 44 };
noutram 0:397b84c74d17 45 }
noutram 0:397b84c74d17 46