Marko Spremic
/
19E042PIM_T1_2020_0066
Marko Spremic 2020/0066
main.cpp@0:a95a1295484c, 2021-11-06 (annotated)
- Committer:
- markospremic
- Date:
- Sat Nov 06 08:15:13 2021 +0000
- Revision:
- 0:a95a1295484c
Marko Spremic 2020/0066
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
markospremic | 0:a95a1295484c | 1 | /* |
markospremic | 0:a95a1295484c | 2 | *Marko Spremic |
markospremic | 0:a95a1295484c | 3 | *Indeks: 2020/0066 |
markospremic | 0:a95a1295484c | 4 | */ |
markospremic | 0:a95a1295484c | 5 | //Ukljucivanje biblioteka: |
markospremic | 0:a95a1295484c | 6 | |
markospremic | 0:a95a1295484c | 7 | #include "mbed.h" |
markospremic | 0:a95a1295484c | 8 | |
markospremic | 0:a95a1295484c | 9 | //Definisanje direktiva: |
markospremic | 0:a95a1295484c | 10 | #define null 0 |
markospremic | 0:a95a1295484c | 11 | #define one 1 |
markospremic | 0:a95a1295484c | 12 | #define ADD(x) x+=1; |
markospremic | 0:a95a1295484c | 13 | #define DEC(x) x-=1; |
markospremic | 0:a95a1295484c | 14 | #define time 8 |
markospremic | 0:a95a1295484c | 15 | #define CHECK(x) if(x > 15) x = 0; |
markospremic | 0:a95a1295484c | 16 | #define CHECK_0(x) if(x < 0) x = 15; |
markospremic | 0:a95a1295484c | 17 | |
markospremic | 0:a95a1295484c | 18 | //Definisanje glavnih promenljivih: |
markospremic | 0:a95a1295484c | 19 | |
markospremic | 0:a95a1295484c | 20 | BusOut led_dis(PA_10, PA_9, PA_8, PB_10, PB_5, PB_4, PB_3, PA_2); |
markospremic | 0:a95a1295484c | 21 | DigitalOut SEL2(PC_7); |
markospremic | 0:a95a1295484c | 22 | DigitalOut SEL1(PB_6); |
markospremic | 0:a95a1295484c | 23 | DigitalIn btn1(PC_9); |
markospremic | 0:a95a1295484c | 24 | DigitalIn btn2(PC_8); |
markospremic | 0:a95a1295484c | 25 | |
markospremic | 0:a95a1295484c | 26 | |
markospremic | 0:a95a1295484c | 27 | //Definisanje pomocne funkcije: |
markospremic | 0:a95a1295484c | 28 | void write_num(int broj) |
markospremic | 0:a95a1295484c | 29 | { |
markospremic | 0:a95a1295484c | 30 | switch(broj) |
markospremic | 0:a95a1295484c | 31 | { |
markospremic | 0:a95a1295484c | 32 | case 0: led_dis = 0xC0; break; |
markospremic | 0:a95a1295484c | 33 | case 1: led_dis = 0xF9; break; |
markospremic | 0:a95a1295484c | 34 | case 2: led_dis = 0xA4; break; |
markospremic | 0:a95a1295484c | 35 | case 3: led_dis = 0xB0; break; |
markospremic | 0:a95a1295484c | 36 | case 4: led_dis = 0x99; break; |
markospremic | 0:a95a1295484c | 37 | case 5: led_dis = 0x92; break; |
markospremic | 0:a95a1295484c | 38 | case 6: led_dis = 0x82; break; |
markospremic | 0:a95a1295484c | 39 | case 7: led_dis = 0xF8; break; |
markospremic | 0:a95a1295484c | 40 | case 8: led_dis = 0x80; break; |
markospremic | 0:a95a1295484c | 41 | case 9: led_dis = 0x90; break; |
markospremic | 0:a95a1295484c | 42 | } |
markospremic | 0:a95a1295484c | 43 | } |
markospremic | 0:a95a1295484c | 44 | |
markospremic | 0:a95a1295484c | 45 | //Definisanje glavne funkcije: |
markospremic | 0:a95a1295484c | 46 | |
markospremic | 0:a95a1295484c | 47 | int main() |
markospremic | 0:a95a1295484c | 48 | { |
markospremic | 0:a95a1295484c | 49 | int x = null, ButtonReleased1 = 0, ButtonReleased2 = 0; |
markospremic | 0:a95a1295484c | 50 | while(1) |
markospremic | 0:a95a1295484c | 51 | { |
markospremic | 0:a95a1295484c | 52 | SEL2.write(0); |
markospremic | 0:a95a1295484c | 53 | SEL1.write(1); |
markospremic | 0:a95a1295484c | 54 | write_num(x%10); |
markospremic | 0:a95a1295484c | 55 | wait_ms(time); |
markospremic | 0:a95a1295484c | 56 | if(x > 9) |
markospremic | 0:a95a1295484c | 57 | { |
markospremic | 0:a95a1295484c | 58 | SEL2.write(1); |
markospremic | 0:a95a1295484c | 59 | SEL1.write(0); |
markospremic | 0:a95a1295484c | 60 | write_num(one); |
markospremic | 0:a95a1295484c | 61 | wait_ms(time); |
markospremic | 0:a95a1295484c | 62 | } |
markospremic | 0:a95a1295484c | 63 | if(!btn1) |
markospremic | 0:a95a1295484c | 64 | { |
markospremic | 0:a95a1295484c | 65 | if(ButtonReleased1) |
markospremic | 0:a95a1295484c | 66 | { |
markospremic | 0:a95a1295484c | 67 | ADD(x) |
markospremic | 0:a95a1295484c | 68 | CHECK(x) |
markospremic | 0:a95a1295484c | 69 | ButtonReleased1 = 0; |
markospremic | 0:a95a1295484c | 70 | } |
markospremic | 0:a95a1295484c | 71 | wait_ms(2 * time); |
markospremic | 0:a95a1295484c | 72 | } |
markospremic | 0:a95a1295484c | 73 | else |
markospremic | 0:a95a1295484c | 74 | ButtonReleased1 = 1; |
markospremic | 0:a95a1295484c | 75 | |
markospremic | 0:a95a1295484c | 76 | if(!btn2) |
markospremic | 0:a95a1295484c | 77 | { |
markospremic | 0:a95a1295484c | 78 | if(ButtonReleased2) |
markospremic | 0:a95a1295484c | 79 | { |
markospremic | 0:a95a1295484c | 80 | DEC(x) |
markospremic | 0:a95a1295484c | 81 | CHECK_0(x) |
markospremic | 0:a95a1295484c | 82 | ButtonReleased2 = 0; |
markospremic | 0:a95a1295484c | 83 | } |
markospremic | 0:a95a1295484c | 84 | |
markospremic | 0:a95a1295484c | 85 | } |
markospremic | 0:a95a1295484c | 86 | else |
markospremic | 0:a95a1295484c | 87 | ButtonReleased2 = 1; |
markospremic | 0:a95a1295484c | 88 | } |
markospremic | 0:a95a1295484c | 89 | } |