Marko Spremic
/
19E042PIM_T1_2020_0066
Marko Spremic 2020/0066
Revision 0:a95a1295484c, committed 2021-11-06
- Comitter:
- markospremic
- Date:
- Sat Nov 06 08:15:13 2021 +0000
- Commit message:
- Marko Spremic 2020/0066
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Nov 06 08:15:13 2021 +0000 @@ -0,0 +1,89 @@ +/* + *Marko Spremic + *Indeks: 2020/0066 + */ + //Ukljucivanje biblioteka: + + #include "mbed.h" + + //Definisanje direktiva: + #define null 0 + #define one 1 + #define ADD(x) x+=1; + #define DEC(x) x-=1; + #define time 8 + #define CHECK(x) if(x > 15) x = 0; + #define CHECK_0(x) if(x < 0) x = 15; + + //Definisanje glavnih promenljivih: + + BusOut led_dis(PA_10, PA_9, PA_8, PB_10, PB_5, PB_4, PB_3, PA_2); + DigitalOut SEL2(PC_7); + DigitalOut SEL1(PB_6); + DigitalIn btn1(PC_9); + DigitalIn btn2(PC_8); + + + //Definisanje pomocne funkcije: + void write_num(int broj) + { + switch(broj) + { + case 0: led_dis = 0xC0; break; + case 1: led_dis = 0xF9; break; + case 2: led_dis = 0xA4; break; + case 3: led_dis = 0xB0; break; + case 4: led_dis = 0x99; break; + case 5: led_dis = 0x92; break; + case 6: led_dis = 0x82; break; + case 7: led_dis = 0xF8; break; + case 8: led_dis = 0x80; break; + case 9: led_dis = 0x90; break; + } + } + + //Definisanje glavne funkcije: + +int main() +{ + int x = null, ButtonReleased1 = 0, ButtonReleased2 = 0; + while(1) + { + SEL2.write(0); + SEL1.write(1); + write_num(x%10); + wait_ms(time); + if(x > 9) + { + SEL2.write(1); + SEL1.write(0); + write_num(one); + wait_ms(time); + } + if(!btn1) + { + if(ButtonReleased1) + { + ADD(x) + CHECK(x) + ButtonReleased1 = 0; + } + wait_ms(2 * time); + } + else + ButtonReleased1 = 1; + + if(!btn2) + { + if(ButtonReleased2) + { + DEC(x) + CHECK_0(x) + ButtonReleased2 = 0; + } + + } + else + ButtonReleased2 = 1; + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Nov 06 08:15:13 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file