Isidora Milivojević
/
19E042PIM_T2_2020_0214
Isidora Milivojevic 2020/0214
main.cpp@0:114829cedd35, 2021-11-13 (annotated)
- Committer:
- soconstruct
- Date:
- Sat Nov 13 09:17:07 2021 +0000
- Revision:
- 0:114829cedd35
Isidora Milivojevic 2020/0214
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
soconstruct | 0:114829cedd35 | 1 | /* Isidora Milivojevic |
soconstruct | 0:114829cedd35 | 2 | * 2020/0214 |
soconstruct | 0:114829cedd35 | 3 | * ETF Beograd |
soconstruct | 0:114829cedd35 | 4 | */ |
soconstruct | 0:114829cedd35 | 5 | |
soconstruct | 0:114829cedd35 | 6 | // Uvoz biblioteka |
soconstruct | 0:114829cedd35 | 7 | #include "mbed.h" |
soconstruct | 0:114829cedd35 | 8 | |
soconstruct | 0:114829cedd35 | 9 | // Definisanje makroa |
soconstruct | 0:114829cedd35 | 10 | #define WAIT 0.1 |
soconstruct | 0:114829cedd35 | 11 | #define ACTIVE 0 |
soconstruct | 0:114829cedd35 | 12 | #define NOT_ACTIVE 1 |
soconstruct | 0:114829cedd35 | 13 | |
soconstruct | 0:114829cedd35 | 14 | //Globalne promenljive |
soconstruct | 0:114829cedd35 | 15 | AnalogIn pot1(PA_0); |
soconstruct | 0:114829cedd35 | 16 | AnalogIn pot2(PA_1); |
soconstruct | 0:114829cedd35 | 17 | InterruptIn sw1(PC_9); |
soconstruct | 0:114829cedd35 | 18 | PwmOut buzz(PA_11); |
soconstruct | 0:114829cedd35 | 19 | DigitalOut select1(PC_7); |
soconstruct | 0:114829cedd35 | 20 | DigitalOut select2(PB_6); |
soconstruct | 0:114829cedd35 | 21 | BusOut display(PA_10, PA_9, PA_8, PB_10, PB_5, PB_4, PB_3); |
soconstruct | 0:114829cedd35 | 22 | int j = 0; |
soconstruct | 0:114829cedd35 | 23 | int d = 0; |
soconstruct | 0:114829cedd35 | 24 | int digits[11] = { 0b1000000, //0 |
soconstruct | 0:114829cedd35 | 25 | 0b1111001, //1 |
soconstruct | 0:114829cedd35 | 26 | 0b0100100, //2 |
soconstruct | 0:114829cedd35 | 27 | 0b0110000, //3 |
soconstruct | 0:114829cedd35 | 28 | 0b0011001, //4 |
soconstruct | 0:114829cedd35 | 29 | 0b0010010, //5 |
soconstruct | 0:114829cedd35 | 30 | 0b0000010, //6 |
soconstruct | 0:114829cedd35 | 31 | 0b1111000, //7 |
soconstruct | 0:114829cedd35 | 32 | 0b0000000, //8 |
soconstruct | 0:114829cedd35 | 33 | 0b0010000, //9 |
soconstruct | 0:114829cedd35 | 34 | }; |
soconstruct | 0:114829cedd35 | 35 | |
soconstruct | 0:114829cedd35 | 36 | //Prototipi funkcija |
soconstruct | 0:114829cedd35 | 37 | void ISR_sw1(void); |
soconstruct | 0:114829cedd35 | 38 | |
soconstruct | 0:114829cedd35 | 39 | //Glavna funkcija |
soconstruct | 0:114829cedd35 | 40 | int main() { |
soconstruct | 0:114829cedd35 | 41 | sw1.fall(&ISR_sw1); |
soconstruct | 0:114829cedd35 | 42 | select1.write(NOT_ACTIVE); |
soconstruct | 0:114829cedd35 | 43 | select2.write(NOT_ACTIVE); |
soconstruct | 0:114829cedd35 | 44 | while (true){ |
soconstruct | 0:114829cedd35 | 45 | buzz.period_us(pot2.read()*2000+100); //Menjanje frekvenicje zujalice pomocu pot2 |
soconstruct | 0:114829cedd35 | 46 | buzz.write(pot1.read()); //Menjanje jacine zujalice pomocu pot1 |
soconstruct | 0:114829cedd35 | 47 | j = (int(pot1.read()*100))%10; //Jedinice jacine zvuka |
soconstruct | 0:114829cedd35 | 48 | d = (int(pot1.read()*100))/10; //Desetice jacine zvuka |
soconstruct | 0:114829cedd35 | 49 | } |
soconstruct | 0:114829cedd35 | 50 | } |
soconstruct | 0:114829cedd35 | 51 | |
soconstruct | 0:114829cedd35 | 52 | //Prekidna rutina za pritisak tastera |
soconstruct | 0:114829cedd35 | 53 | void ISR_sw1(){ |
soconstruct | 0:114829cedd35 | 54 | while(true){ |
soconstruct | 0:114829cedd35 | 55 | if(!d) { |
soconstruct | 0:114829cedd35 | 56 | display.write(digits[j]); |
soconstruct | 0:114829cedd35 | 57 | select1.write(ACTIVE); |
soconstruct | 0:114829cedd35 | 58 | select2.write(NOT_ACTIVE); |
soconstruct | 0:114829cedd35 | 59 | } else { |
soconstruct | 0:114829cedd35 | 60 | display.write(digits[d]); |
soconstruct | 0:114829cedd35 | 61 | select1.write(NOT_ACTIVE); |
soconstruct | 0:114829cedd35 | 62 | select2.write(ACTIVE); |
soconstruct | 0:114829cedd35 | 63 | wait_ms(10); |
soconstruct | 0:114829cedd35 | 64 | display.write(digits[j]); |
soconstruct | 0:114829cedd35 | 65 | select1.write(ACTIVE); |
soconstruct | 0:114829cedd35 | 66 | select2.write(NOT_ACTIVE); |
soconstruct | 0:114829cedd35 | 67 | wait_ms(10); |
soconstruct | 0:114829cedd35 | 68 | } |
soconstruct | 0:114829cedd35 | 69 | } |
soconstruct | 0:114829cedd35 | 70 | } |