![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Drugi test iz PIM-a Milan Takic 2020/0690
main.cpp@0:208b1e7384da, 2021-11-13 (annotated)
- Committer:
- milant
- Date:
- Sat Nov 13 08:51:20 2021 +0000
- Revision:
- 0:208b1e7384da
Milan Takic 2020/0690
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
milant | 0:208b1e7384da | 1 | /* |
milant | 0:208b1e7384da | 2 | Drugi test iz PIM-a |
milant | 0:208b1e7384da | 3 | Milan Takic 2020/0690 |
milant | 0:208b1e7384da | 4 | 13.11.2021 |
milant | 0:208b1e7384da | 5 | */ |
milant | 0:208b1e7384da | 6 | |
milant | 0:208b1e7384da | 7 | //uvezivanje biblioteka |
milant | 0:208b1e7384da | 8 | #include "mbed.h" |
milant | 0:208b1e7384da | 9 | |
milant | 0:208b1e7384da | 10 | //definisanje makroa |
milant | 0:208b1e7384da | 11 | #define A PA_10 |
milant | 0:208b1e7384da | 12 | #define B PA_9 |
milant | 0:208b1e7384da | 13 | #define C PA_8 |
milant | 0:208b1e7384da | 14 | #define D PB_10 |
milant | 0:208b1e7384da | 15 | #define E PB_5 |
milant | 0:208b1e7384da | 16 | #define F PB_4 |
milant | 0:208b1e7384da | 17 | #define G PB_3 |
milant | 0:208b1e7384da | 18 | #define SEL_1 PB_6 |
milant | 0:208b1e7384da | 19 | #define SEL_2 PC_7 |
milant | 0:208b1e7384da | 20 | #define PWM_PERIOD 15 |
milant | 0:208b1e7384da | 21 | #define V_MULTIPLIER 3.3f |
milant | 0:208b1e7384da | 22 | #define DUTY_CYCLE 0.5f |
milant | 0:208b1e7384da | 23 | #define MULTIPLIER 5 |
milant | 0:208b1e7384da | 24 | |
milant | 0:208b1e7384da | 25 | //globalne promenljive |
milant | 0:208b1e7384da | 26 | |
milant | 0:208b1e7384da | 27 | BusOut display(A,B,C,D,E,F,G); |
milant | 0:208b1e7384da | 28 | DigitalOut select1(SEL_1); |
milant | 0:208b1e7384da | 29 | DigitalOut select2(SEL_2); |
milant | 0:208b1e7384da | 30 | AnalogIn pot1 (PA_0); |
milant | 0:208b1e7384da | 31 | AnalogIn pot2 (PA_1); |
milant | 0:208b1e7384da | 32 | InterruptIn sw1(PC_9); |
milant | 0:208b1e7384da | 33 | PwmOut buzzer(PA_11); |
milant | 0:208b1e7384da | 34 | const int digit[] = {0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010, 0b0000010, 0b1111000, 0b0000000, 0b0010000}; |
milant | 0:208b1e7384da | 35 | int i = 0; |
milant | 0:208b1e7384da | 36 | int j = 0; |
milant | 0:208b1e7384da | 37 | int flag = 0; |
milant | 0:208b1e7384da | 38 | |
milant | 0:208b1e7384da | 39 | //deklaracija funkcija |
milant | 0:208b1e7384da | 40 | void ISR_sw1(); |
milant | 0:208b1e7384da | 41 | //glavna funkcija |
milant | 0:208b1e7384da | 42 | int main(){ |
milant | 0:208b1e7384da | 43 | select1.write(1); |
milant | 0:208b1e7384da | 44 | select2.write(1); |
milant | 0:208b1e7384da | 45 | sw1.fall(&ISR_sw1); |
milant | 0:208b1e7384da | 46 | buzzer.period_ms(PWM_PERIOD); |
milant | 0:208b1e7384da | 47 | |
milant | 0:208b1e7384da | 48 | while(true){ |
milant | 0:208b1e7384da | 49 | buzzer.write(pot1.read()); |
milant | 0:208b1e7384da | 50 | i = pot1.read()*10; |
milant | 0:208b1e7384da | 51 | j = pot1.read()*10; |
milant | 0:208b1e7384da | 52 | if(flag){ |
milant | 0:208b1e7384da | 53 | select2.write(1); |
milant | 0:208b1e7384da | 54 | select1.write(0); |
milant | 0:208b1e7384da | 55 | display = digit[i]; |
milant | 0:208b1e7384da | 56 | wait_us(100); |
milant | 0:208b1e7384da | 57 | select1.write(1); |
milant | 0:208b1e7384da | 58 | select2.write(0); |
milant | 0:208b1e7384da | 59 | display = digit[j]; |
milant | 0:208b1e7384da | 60 | wait_us(100); |
milant | 0:208b1e7384da | 61 | flag = 0; |
milant | 0:208b1e7384da | 62 | } |
milant | 0:208b1e7384da | 63 | } |
milant | 0:208b1e7384da | 64 | |
milant | 0:208b1e7384da | 65 | } |
milant | 0:208b1e7384da | 66 | |
milant | 0:208b1e7384da | 67 | void ISR_sw1(){ |
milant | 0:208b1e7384da | 68 | flag = 1; |
milant | 0:208b1e7384da | 69 | } |
milant | 0:208b1e7384da | 70 | |
milant | 0:208b1e7384da | 71 | // :( |