Marko Spremic
/
19E042PIM_T1_2020_0066verzijaposlednja
Marko Spremic 2020/0066 verzija poslednja
main.cpp@1:5422c10009a3, 2021-11-06 (annotated)
- Committer:
- markospremic
- Date:
- Sat Nov 06 09:46:07 2021 +0000
- Revision:
- 1:5422c10009a3
- Parent:
- 0:a95a1295484c
Marko Spremic 2020/0066 verzija poslednja
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 | 1:5422c10009a3 | 15 | #define time2 50 |
markospremic | 0:a95a1295484c | 16 | #define CHECK(x) if(x > 15) x = 0; |
markospremic | 0:a95a1295484c | 17 | #define CHECK_0(x) if(x < 0) x = 15; |
markospremic | 0:a95a1295484c | 18 | |
markospremic | 0:a95a1295484c | 19 | //Definisanje glavnih promenljivih: |
markospremic | 0:a95a1295484c | 20 | |
markospremic | 0:a95a1295484c | 21 | BusOut led_dis(PA_10, PA_9, PA_8, PB_10, PB_5, PB_4, PB_3, PA_2); |
markospremic | 0:a95a1295484c | 22 | DigitalOut SEL2(PC_7); |
markospremic | 0:a95a1295484c | 23 | DigitalOut SEL1(PB_6); |
markospremic | 0:a95a1295484c | 24 | DigitalIn btn1(PC_9); |
markospremic | 0:a95a1295484c | 25 | DigitalIn btn2(PC_8); |
markospremic | 0:a95a1295484c | 26 | |
markospremic | 0:a95a1295484c | 27 | |
markospremic | 0:a95a1295484c | 28 | //Definisanje pomocne funkcije: |
markospremic | 0:a95a1295484c | 29 | void write_num(int broj) |
markospremic | 0:a95a1295484c | 30 | { |
markospremic | 0:a95a1295484c | 31 | switch(broj) |
markospremic | 0:a95a1295484c | 32 | { |
markospremic | 0:a95a1295484c | 33 | case 0: led_dis = 0xC0; break; |
markospremic | 0:a95a1295484c | 34 | case 1: led_dis = 0xF9; break; |
markospremic | 0:a95a1295484c | 35 | case 2: led_dis = 0xA4; break; |
markospremic | 0:a95a1295484c | 36 | case 3: led_dis = 0xB0; break; |
markospremic | 0:a95a1295484c | 37 | case 4: led_dis = 0x99; break; |
markospremic | 0:a95a1295484c | 38 | case 5: led_dis = 0x92; break; |
markospremic | 0:a95a1295484c | 39 | case 6: led_dis = 0x82; break; |
markospremic | 0:a95a1295484c | 40 | case 7: led_dis = 0xF8; break; |
markospremic | 0:a95a1295484c | 41 | case 8: led_dis = 0x80; break; |
markospremic | 0:a95a1295484c | 42 | case 9: led_dis = 0x90; break; |
markospremic | 1:5422c10009a3 | 43 | default: led_dis = 0xFF; |
markospremic | 0:a95a1295484c | 44 | } |
markospremic | 0:a95a1295484c | 45 | } |
markospremic | 0:a95a1295484c | 46 | |
markospremic | 0:a95a1295484c | 47 | //Definisanje glavne funkcije: |
markospremic | 0:a95a1295484c | 48 | |
markospremic | 0:a95a1295484c | 49 | int main() |
markospremic | 0:a95a1295484c | 50 | { |
markospremic | 1:5422c10009a3 | 51 | int x = null, x1 = null, x2 = null;static char ButtonReleased1 = 1, ButtonReleased2 = 1; |
markospremic | 0:a95a1295484c | 52 | while(1) |
markospremic | 0:a95a1295484c | 53 | { |
markospremic | 1:5422c10009a3 | 54 | x1 = x % 10; |
markospremic | 1:5422c10009a3 | 55 | x2 = (x / 10 == 1)? 1:-1; |
markospremic | 0:a95a1295484c | 56 | SEL2.write(0); |
markospremic | 0:a95a1295484c | 57 | SEL1.write(1); |
markospremic | 1:5422c10009a3 | 58 | write_num(x1); |
markospremic | 0:a95a1295484c | 59 | wait_ms(time); |
markospremic | 1:5422c10009a3 | 60 | |
markospremic | 1:5422c10009a3 | 61 | SEL2.write(1); |
markospremic | 1:5422c10009a3 | 62 | SEL1.write(0); |
markospremic | 1:5422c10009a3 | 63 | write_num(x2); |
markospremic | 1:5422c10009a3 | 64 | wait_ms(time); |
markospremic | 1:5422c10009a3 | 65 | |
markospremic | 1:5422c10009a3 | 66 | if(!btn1 && btn2) |
markospremic | 0:a95a1295484c | 67 | { |
markospremic | 0:a95a1295484c | 68 | if(ButtonReleased1) |
markospremic | 0:a95a1295484c | 69 | { |
markospremic | 0:a95a1295484c | 70 | ADD(x) |
markospremic | 0:a95a1295484c | 71 | CHECK(x) |
markospremic | 0:a95a1295484c | 72 | ButtonReleased1 = 0; |
markospremic | 0:a95a1295484c | 73 | } |
markospremic | 1:5422c10009a3 | 74 | wait_ms(time2); |
markospremic | 0:a95a1295484c | 75 | } |
markospremic | 0:a95a1295484c | 76 | else |
markospremic | 1:5422c10009a3 | 77 | { |
markospremic | 0:a95a1295484c | 78 | ButtonReleased1 = 1; |
markospremic | 1:5422c10009a3 | 79 | } |
markospremic | 1:5422c10009a3 | 80 | if(!btn2 && btn1) |
markospremic | 0:a95a1295484c | 81 | { |
markospremic | 0:a95a1295484c | 82 | if(ButtonReleased2) |
markospremic | 0:a95a1295484c | 83 | { |
markospremic | 0:a95a1295484c | 84 | DEC(x) |
markospremic | 0:a95a1295484c | 85 | CHECK_0(x) |
markospremic | 0:a95a1295484c | 86 | ButtonReleased2 = 0; |
markospremic | 0:a95a1295484c | 87 | } |
markospremic | 1:5422c10009a3 | 88 | wait_ms(time2); |
markospremic | 0:a95a1295484c | 89 | } |
markospremic | 0:a95a1295484c | 90 | else |
markospremic | 1:5422c10009a3 | 91 | { |
markospremic | 0:a95a1295484c | 92 | ButtonReleased2 = 1; |
markospremic | 1:5422c10009a3 | 93 | } |
markospremic | 0:a95a1295484c | 94 | } |
markospremic | 0:a95a1295484c | 95 | } |