Nenad Tepavac
/
19E042PIM_T1_2020_0028
Nenad Tepavac 2020/0028
Diff: main.cpp
- Revision:
- 0:34bc6102fcfb
diff -r 000000000000 -r 34bc6102fcfb main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Nov 06 08:41:29 2021 +0000 @@ -0,0 +1,134 @@ +/* +* Nenad Tepavac 2020/0028 +* Etf Beograd +*/ + +/* +* Biblioteke +*/ +#include "mbed.h" + +/* +* Makroi +*/ +#define NULA 0xC0 +#define KEC 0xF9 +#define DVA 0xA4 +#define TRI 0xB0 +#define CTR 0x99 +#define PET 0x92 +#define SES 0x82 +#define SEAM 0xF8 +#define OSAM 0x80 +#define DE 0x90 + + +BusOut display(PA_10, PA_9, PA_8,PB_10,PB_5, PB_4, PB_3, PB_6, PC_7); +DigitalIn btn(BUTTON1); +DigitalIn sw(PC_9); + +DigitalIn btn2(PC_8); + +int c = 0; +int b = 0; +int b2 = 0; +int s = 0; + +void increment(){ + c++; + if(c > 15) + c = 0; + + switch(c){ + case 0: + display.write(NULA); + break; + case 1: + display.write(KEC); + break; + case 2: + display.write(DVA); + break; + case 3: + display.write(TRI); + break; + case 4: + display.write(CTR); + break; + case 5: + display.write(PET); + break; + case 6: + display.write(SES); + break; + case 7: + display.write(SEAM); + break; + case 8: + display.write(OSAM); + break; + case 9: + display.write(DE); + break; + } +} + +void decrement(){ + c--; + c--; + + if(c == -2) + c = 14; + + increment(); +} + +int main(){ + display.write(NULA); + + while(true){ + if(!btn){ + b = 1; + } + if(btn && b == 1){ + b = 0; + increment(); + } + + if(!sw){ + s = 1; + } + if(sw && s == 1){ + s = 0; + increment(); + } + + + if(btn2){ + b2 = 1; + } + if(!btn2 && b2 == 1){ + b2 = 0; + decrement(); + } + + if(c > 9){ + display.write(0b101111001); + wait_ms(5); + if(c == 10) + display.write(NULA); + if(c == 11) + display.write(KEC); + if(c == 12) + display.write(DVA); + if(c == 13) + display.write(TRI); + if(c == 14) + display.write(CTR); + if(c == 15) + display.write(PET); + wait_ms(5); + } + } + +} \ No newline at end of file