![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Milan Takic 2020/0690 sedmosegmentni displej
main.cpp@0:926a55324bcc, 2021-11-06 (annotated)
- Committer:
- milant
- Date:
- Sat Nov 06 09:28:19 2021 +0000
- Revision:
- 0:926a55324bcc
Milan Takic 2020/0690
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
milant | 0:926a55324bcc | 1 | // uvoz biblioteke |
milant | 0:926a55324bcc | 2 | |
milant | 0:926a55324bcc | 3 | #include "mbed.h" |
milant | 0:926a55324bcc | 4 | |
milant | 0:926a55324bcc | 5 | // definisanje direktiva |
milant | 0:926a55324bcc | 6 | |
milant | 0:926a55324bcc | 7 | #define A PA_10 |
milant | 0:926a55324bcc | 8 | #define B PA_9 |
milant | 0:926a55324bcc | 9 | #define C PA_8 |
milant | 0:926a55324bcc | 10 | #define D PB_10 |
milant | 0:926a55324bcc | 11 | #define E PB_5 |
milant | 0:926a55324bcc | 12 | #define F PB_4 |
milant | 0:926a55324bcc | 13 | #define G PB_3 |
milant | 0:926a55324bcc | 14 | #define SEL_1 PB_6 |
milant | 0:926a55324bcc | 15 | #define SEL_2 PC_7 |
milant | 0:926a55324bcc | 16 | #define SW1(PC_9) |
milant | 0:926a55324bcc | 17 | #define SW2(PC_8) |
milant | 0:926a55324bcc | 18 | |
milant | 0:926a55324bcc | 19 | // kreiranje objekata |
milant | 0:926a55324bcc | 20 | |
milant | 0:926a55324bcc | 21 | const int digit[] = {0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010, 0b0000010, 0b1111000, 0b0000000, 0b0010000}; |
milant | 0:926a55324bcc | 22 | BusOut display(A,B,C,D,E,F,G,SEL_1,SEL_2); |
milant | 0:926a55324bcc | 23 | DigitalOut d1(SEL_1); |
milant | 0:926a55324bcc | 24 | DigitalOut d2(SEL_2); |
milant | 0:926a55324bcc | 25 | DigitalIn sw1(PC_9); |
milant | 0:926a55324bcc | 26 | DigitalIn sw2(PC_8); |
milant | 0:926a55324bcc | 27 | |
milant | 0:926a55324bcc | 28 | // glavna funkcija |
milant | 0:926a55324bcc | 29 | |
milant | 0:926a55324bcc | 30 | int main(){ |
milant | 0:926a55324bcc | 31 | |
milant | 0:926a55324bcc | 32 | //incijalizovanje promenljivih |
milant | 0:926a55324bcc | 33 | |
milant | 0:926a55324bcc | 34 | static char button1_released = 0; |
milant | 0:926a55324bcc | 35 | static char button2_released = 0; |
milant | 0:926a55324bcc | 36 | d1.write(1); |
milant | 0:926a55324bcc | 37 | d2.write(0); |
milant | 0:926a55324bcc | 38 | display = digit[0]; |
milant | 0:926a55324bcc | 39 | int i =-1; |
milant | 0:926a55324bcc | 40 | |
milant | 0:926a55324bcc | 41 | // glavna petlja |
milant | 0:926a55324bcc | 42 | |
milant | 0:926a55324bcc | 43 | while(true){ |
milant | 0:926a55324bcc | 44 | |
milant | 0:926a55324bcc | 45 | if(!sw2){ |
milant | 0:926a55324bcc | 46 | if(button2_released){ |
milant | 0:926a55324bcc | 47 | |
milant | 0:926a55324bcc | 48 | if(i == -1){ |
milant | 0:926a55324bcc | 49 | i = 9; |
milant | 0:926a55324bcc | 50 | } |
milant | 0:926a55324bcc | 51 | display = digit[i--]; |
milant | 0:926a55324bcc | 52 | button2_released = 0; |
milant | 0:926a55324bcc | 53 | } |
milant | 0:926a55324bcc | 54 | } |
milant | 0:926a55324bcc | 55 | else{ |
milant | 0:926a55324bcc | 56 | button2_released = 1; |
milant | 0:926a55324bcc | 57 | } |
milant | 0:926a55324bcc | 58 | wait_ms(50); |
milant | 0:926a55324bcc | 59 | |
milant | 0:926a55324bcc | 60 | if(!sw1){ |
milant | 0:926a55324bcc | 61 | if(button1_released){ |
milant | 0:926a55324bcc | 62 | |
milant | 0:926a55324bcc | 63 | if(i == 10 ){ |
milant | 0:926a55324bcc | 64 | i = -1; |
milant | 0:926a55324bcc | 65 | } |
milant | 0:926a55324bcc | 66 | display = digit[i++]; |
milant | 0:926a55324bcc | 67 | button1_released = 0; |
milant | 0:926a55324bcc | 68 | } |
milant | 0:926a55324bcc | 69 | } |
milant | 0:926a55324bcc | 70 | else{ |
milant | 0:926a55324bcc | 71 | button1_released = 1; |
milant | 0:926a55324bcc | 72 | } |
milant | 0:926a55324bcc | 73 | wait_ms(50); |
milant | 0:926a55324bcc | 74 | } |
milant | 0:926a55324bcc | 75 | } |
milant | 0:926a55324bcc | 76 | |
milant | 0:926a55324bcc | 77 | |
milant | 0:926a55324bcc | 78 | //imao sam problem gde su se oba displeja palila iako sam na pocetku prvi stavio na 1 drugi na 0 |
milant | 0:926a55324bcc | 79 | |
milant | 0:926a55324bcc | 80 | //cisto da probam |
milant | 0:926a55324bcc | 81 | /*while(true){ |
milant | 0:926a55324bcc | 82 | if(i == 9){ |
milant | 0:926a55324bcc | 83 | i = -1; |
milant | 0:926a55324bcc | 84 | } |
milant | 0:926a55324bcc | 85 | display = digit[++i]; |
milant | 0:926a55324bcc | 86 | |
milant | 0:926a55324bcc | 87 | wait_ms(1000); |
milant | 0:926a55324bcc | 88 | } |
milant | 0:926a55324bcc | 89 | */ |