![](/media/cache/group/tvz-logo.png.50x50_q85.png)
Final
Dependencies: mbed NadzorTemperature
main.cpp@0:23dcc83123c6, 2021-09-21 (annotated)
- Committer:
- fjakic
- Date:
- Tue Sep 21 15:45:16 2021 +0000
- Revision:
- 0:23dcc83123c6
Final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fjakic | 0:23dcc83123c6 | 1 | #include "mbed.h" |
fjakic | 0:23dcc83123c6 | 2 | #include "ledSignalizacija.h" |
fjakic | 0:23dcc83123c6 | 3 | |
fjakic | 0:23dcc83123c6 | 4 | Serial pc(USBTX, USBRX); |
fjakic | 0:23dcc83123c6 | 5 | AnalogIn temperaturniSenzor(A0); |
fjakic | 0:23dcc83123c6 | 6 | PwmOut buzzer(D5); |
fjakic | 0:23dcc83123c6 | 7 | Timer timer; |
fjakic | 0:23dcc83123c6 | 8 | Ticker zvucniSignal; |
fjakic | 0:23dcc83123c6 | 9 | InterruptIn button(D7, PullDown); |
fjakic | 0:23dcc83123c6 | 10 | Timer debounce; |
fjakic | 0:23dcc83123c6 | 11 | LedSignalizacija ledSig(D4, D3, D2); |
fjakic | 0:23dcc83123c6 | 12 | |
fjakic | 0:23dcc83123c6 | 13 | void provjeraSenzora(); |
fjakic | 0:23dcc83123c6 | 14 | void upozorenje(); |
fjakic | 0:23dcc83123c6 | 15 | |
fjakic | 0:23dcc83123c6 | 16 | int main() |
fjakic | 0:23dcc83123c6 | 17 | { |
fjakic | 0:23dcc83123c6 | 18 | debounce.start(); |
fjakic | 0:23dcc83123c6 | 19 | button.rise(&upozorenje); |
fjakic | 0:23dcc83123c6 | 20 | zvucniSignal.attach(&provjeraSenzora, 0.5); |
fjakic | 0:23dcc83123c6 | 21 | buzzer.period_ms(20); |
fjakic | 0:23dcc83123c6 | 22 | |
fjakic | 0:23dcc83123c6 | 23 | while(1){ |
fjakic | 0:23dcc83123c6 | 24 | pc.printf("Temperatura: %f\r", temperaturniSenzor.read() * 100); |
fjakic | 0:23dcc83123c6 | 25 | ledSig.postaviLedSignalizaciju(temperaturniSenzor); |
fjakic | 0:23dcc83123c6 | 26 | wait(0.5); |
fjakic | 0:23dcc83123c6 | 27 | } |
fjakic | 0:23dcc83123c6 | 28 | } |
fjakic | 0:23dcc83123c6 | 29 | |
fjakic | 0:23dcc83123c6 | 30 | void provjeraSenzora(){ |
fjakic | 0:23dcc83123c6 | 31 | if(temperaturniSenzor >= 0.9) { |
fjakic | 0:23dcc83123c6 | 32 | if(timer.read() == 0){ |
fjakic | 0:23dcc83123c6 | 33 | timer.start(); |
fjakic | 0:23dcc83123c6 | 34 | buzzer = 0; |
fjakic | 0:23dcc83123c6 | 35 | } |
fjakic | 0:23dcc83123c6 | 36 | if(timer.read() >= 2){ |
fjakic | 0:23dcc83123c6 | 37 | buzzer = 0.5; |
fjakic | 0:23dcc83123c6 | 38 | } |
fjakic | 0:23dcc83123c6 | 39 | } |
fjakic | 0:23dcc83123c6 | 40 | else{ |
fjakic | 0:23dcc83123c6 | 41 | buzzer = 0; |
fjakic | 0:23dcc83123c6 | 42 | timer.reset(); |
fjakic | 0:23dcc83123c6 | 43 | } |
fjakic | 0:23dcc83123c6 | 44 | } |
fjakic | 0:23dcc83123c6 | 45 | |
fjakic | 0:23dcc83123c6 | 46 | void upozorenje() { |
fjakic | 0:23dcc83123c6 | 47 | if(debounce.read_ms() > 200) { |
fjakic | 0:23dcc83123c6 | 48 | buzzer = 0.1; |
fjakic | 0:23dcc83123c6 | 49 | ledSig.upaliSveLedice(2); |
fjakic | 0:23dcc83123c6 | 50 | debounce.reset(); |
fjakic | 0:23dcc83123c6 | 51 | buzzer = 0; |
fjakic | 0:23dcc83123c6 | 52 | } |
fjakic | 0:23dcc83123c6 | 53 | } |