University of Plymouth - Stages 1, 2 and 3 / Mbed OS Task330
Committer:
noutram
Date:
Mon Oct 23 12:28:09 2017 +0000
Revision:
3:a39db8aa11e8
Parent:
2:ca251bdda621
Child:
4:f30ca79f4676
Simplify

Who changed what in which revision?

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