Andrew Bell
/
repositorylab2
nearly working
Diff: main.cpp
- Revision:
- 0:0bf29dbfe4d5
diff -r 000000000000 -r 0bf29dbfe4d5 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Feb 03 16:04:38 2021 +0000 @@ -0,0 +1,62 @@ +#include "mbed.h" + +BusOut LED_Disp(p7,p11,p9,p8,p5,p6,p10,p12); + +DigitalIn plusbutton(p14); +DigitalIn minusbutton(p15); +DigitalOut LED(LED1); +DigitalOut LED_2 (LED2); + +void DisplayNumber(int); + +int main() +{ + int counter = 0; + DisplayNumber(counter); + + while(1) + { + if (plusbutton == 1) + { + LED = 1; + wait(1.0); + LED = 0; + counter++; + DisplayNumber(counter); + wait(0.5); + } + + if (minusbutton == 1) + { + LED_2 = 1; + wait(1.0); + LED_2 = 0; + counter--; + DisplayNumber(counter); + wait(0.5); + } + } +} +void DisplayNumber(int num) + +{ + switch(num) + { + case 0: + LED_Disp = ~0x3F; // bit pattern for 0 + break; + + case 1: + LED_Disp = ~0x06; + break; + + case 2: + LED_Disp = ~0x5B; + break; + } +} + + + + + \ No newline at end of file