![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Mihajlo Djordjevic 2020/0438
main.cpp@0:849fcc3d83a1, 2021-11-13 (annotated)
- Committer:
- mixidj
- Date:
- Sat Nov 13 08:59:34 2021 +0000
- Revision:
- 0:849fcc3d83a1
Test 2 Mihajlo Djordjevic
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mixidj | 0:849fcc3d83a1 | 1 | // Mihajlo Djordjevic 2020/0438 |
mixidj | 0:849fcc3d83a1 | 2 | // Uvoz biblioteke |
mixidj | 0:849fcc3d83a1 | 3 | #include "mbed.h" |
mixidj | 0:849fcc3d83a1 | 4 | //Makro |
mixidj | 0:849fcc3d83a1 | 5 | #define POLLING_PERIOD 20 |
mixidj | 0:849fcc3d83a1 | 6 | #define MAX_POT1 0.9f |
mixidj | 0:849fcc3d83a1 | 7 | #define MAX_POT2 0.8f |
mixidj | 0:849fcc3d83a1 | 8 | #define MAX_PERIOD 1.05 |
mixidj | 0:849fcc3d83a1 | 9 | // Glavne promenljive |
mixidj | 0:849fcc3d83a1 | 10 | PwmOut buzzer(PA_11); |
mixidj | 0:849fcc3d83a1 | 11 | AnalogIn pot1(PA_0); |
mixidj | 0:849fcc3d83a1 | 12 | AnalogIn pot2(PA_1); |
mixidj | 0:849fcc3d83a1 | 13 | InterruptIn button(PC_9); |
mixidj | 0:849fcc3d83a1 | 14 | |
mixidj | 0:849fcc3d83a1 | 15 | |
mixidj | 0:849fcc3d83a1 | 16 | // Funkcije |
mixidj | 0:849fcc3d83a1 | 17 | void ISR_procenat(void); |
mixidj | 0:849fcc3d83a1 | 18 | |
mixidj | 0:849fcc3d83a1 | 19 | int main () { |
mixidj | 0:849fcc3d83a1 | 20 | |
mixidj | 0:849fcc3d83a1 | 21 | |
mixidj | 0:849fcc3d83a1 | 22 | while(true) { |
mixidj | 0:849fcc3d83a1 | 23 | button.fall(ISR_procenat); |
mixidj | 0:849fcc3d83a1 | 24 | if(pot1.read() < MAX_POT1){ |
mixidj | 0:849fcc3d83a1 | 25 | buzzer = pot1.read(); |
mixidj | 0:849fcc3d83a1 | 26 | } |
mixidj | 0:849fcc3d83a1 | 27 | else buzzer = MAX_POT1; |
mixidj | 0:849fcc3d83a1 | 28 | |
mixidj | 0:849fcc3d83a1 | 29 | |
mixidj | 0:849fcc3d83a1 | 30 | printf(" pot1 : %1.2f pot2 : %1.2f \r", pot1.read(),pot2.read()); |
mixidj | 0:849fcc3d83a1 | 31 | |
mixidj | 0:849fcc3d83a1 | 32 | float period; |
mixidj | 0:849fcc3d83a1 | 33 | if(pot2.read() < MAX_POT2){ |
mixidj | 0:849fcc3d83a1 | 34 | period = 5 - pot2.read() * 4.95; |
mixidj | 0:849fcc3d83a1 | 35 | buzzer.period_ms(period); |
mixidj | 0:849fcc3d83a1 | 36 | } |
mixidj | 0:849fcc3d83a1 | 37 | else buzzer.period_ms(MAX_PERIOD); |
mixidj | 0:849fcc3d83a1 | 38 | wait_ms(POLLING_PERIOD); |
mixidj | 0:849fcc3d83a1 | 39 | } |
mixidj | 0:849fcc3d83a1 | 40 | } |
mixidj | 0:849fcc3d83a1 | 41 | void ISR_procenat(){ |
mixidj | 0:849fcc3d83a1 | 42 | |
mixidj | 0:849fcc3d83a1 | 43 | } |
mixidj | 0:849fcc3d83a1 | 44 |