![](/media/cache/group/tvz-logo.png.50x50_q85.png)
main
Dependencies: mbed Alarmni_sustav
Fork of Alarm_Barnjak by
main.cpp@1:ffe9956395e9, 2021-05-06 (annotated)
- Committer:
- nbarnjak
- Date:
- Thu May 06 13:55:03 2021 +0000
- Revision:
- 1:ffe9956395e9
- Parent:
- 0:d33881c5ba2d
LED_lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nbarnjak | 0:d33881c5ba2d | 1 | #include "mbed.h" |
nbarnjak | 0:d33881c5ba2d | 2 | #include "klasaLED.h" |
nbarnjak | 0:d33881c5ba2d | 3 | Serial pc(USBTX, USBRX); |
nbarnjak | 1:ffe9956395e9 | 4 | LED_ led1(A0); //alarm-zelena |
nbarnjak | 1:ffe9956395e9 | 5 | LED_ led2(D2);//centrala-žuta-signalna LED |
nbarnjak | 1:ffe9956395e9 | 6 | LED_ led3(D3);//alarm-crvena |
nbarnjak | 1:ffe9956395e9 | 7 | LED_ led4(D4);//centrala-zelena |
nbarnjak | 1:ffe9956395e9 | 8 | LED_ led5(D5);//centrala-crvena |
nbarnjak | 0:d33881c5ba2d | 9 | InterruptIn button(USER_BUTTON); |
nbarnjak | 0:d33881c5ba2d | 10 | Timer senzor; |
nbarnjak | 0:d33881c5ba2d | 11 | Timer alarm; |
nbarnjak | 0:d33881c5ba2d | 12 | Timer debounce; |
nbarnjak | 0:d33881c5ba2d | 13 | void flip() //Hardverski interrupt |
nbarnjak | 0:d33881c5ba2d | 14 | { |
nbarnjak | 0:d33881c5ba2d | 15 | if(debounce.read_ms()>200) { |
nbarnjak | 0:d33881c5ba2d | 16 | led1.status(0); |
nbarnjak | 0:d33881c5ba2d | 17 | led3.status(0); |
nbarnjak | 0:d33881c5ba2d | 18 | led4.status(0); |
nbarnjak | 0:d33881c5ba2d | 19 | led5.status(0); |
nbarnjak | 0:d33881c5ba2d | 20 | int i; |
nbarnjak | 0:d33881c5ba2d | 21 | for(i=0; i<6; i++) { |
nbarnjak | 0:d33881c5ba2d | 22 | led2.flip(); |
nbarnjak | 0:d33881c5ba2d | 23 | led5.flip(); |
nbarnjak | 0:d33881c5ba2d | 24 | wait(0.5); |
nbarnjak | 0:d33881c5ba2d | 25 | senzor.reset(); |
nbarnjak | 0:d33881c5ba2d | 26 | senzor.start(); |
nbarnjak | 0:d33881c5ba2d | 27 | } |
nbarnjak | 0:d33881c5ba2d | 28 | } |
nbarnjak | 0:d33881c5ba2d | 29 | } |
nbarnjak | 0:d33881c5ba2d | 30 | int main() |
nbarnjak | 0:d33881c5ba2d | 31 | { |
nbarnjak | 0:d33881c5ba2d | 32 | debounce.start(); |
nbarnjak | 0:d33881c5ba2d | 33 | button.rise(&flip); |
nbarnjak | 0:d33881c5ba2d | 34 | |
nbarnjak | 0:d33881c5ba2d | 35 | while(1) { |
nbarnjak | 0:d33881c5ba2d | 36 | |
nbarnjak | 0:d33881c5ba2d | 37 | //Početno LED stanje |
nbarnjak | 0:d33881c5ba2d | 38 | led1.status(0); |
nbarnjak | 0:d33881c5ba2d | 39 | led2.status(0); |
nbarnjak | 0:d33881c5ba2d | 40 | led3.status(1); |
nbarnjak | 0:d33881c5ba2d | 41 | led4.status(1); |
nbarnjak | 0:d33881c5ba2d | 42 | led5.status(0); |
nbarnjak | 0:d33881c5ba2d | 43 | |
nbarnjak | 0:d33881c5ba2d | 44 | //Nakon 5 sekundi slijedi detekcija ulaska koji se sa senzora proslijeđuje na centralu |
nbarnjak | 0:d33881c5ba2d | 45 | senzor.start(); |
nbarnjak | 0:d33881c5ba2d | 46 | if (senzor.read() > 5) { |
nbarnjak | 0:d33881c5ba2d | 47 | led3.flip(); |
nbarnjak | 0:d33881c5ba2d | 48 | |
nbarnjak | 0:d33881c5ba2d | 49 | //Dvije sekunde nakon detekcija ulaza upali signalnu LED na centrali |
nbarnjak | 0:d33881c5ba2d | 50 | } |
nbarnjak | 0:d33881c5ba2d | 51 | if (senzor.read() > 7) { |
nbarnjak | 0:d33881c5ba2d | 52 | led2.flip(); |
nbarnjak | 0:d33881c5ba2d | 53 | //Ukoliko centrala nije resetirana unutar 5 sekundi od aktivacije signalne LED, upali alarm i blokiraj centralu i alarm od resetiranja |
nbarnjak | 0:d33881c5ba2d | 54 | } |
nbarnjak | 0:d33881c5ba2d | 55 | if(senzor.read()>12 ) { |
nbarnjak | 0:d33881c5ba2d | 56 | led1.flip(); |
nbarnjak | 0:d33881c5ba2d | 57 | led2.flip(); |
nbarnjak | 0:d33881c5ba2d | 58 | led4.flip(); |
nbarnjak | 0:d33881c5ba2d | 59 | led5.flip(); |
nbarnjak | 0:d33881c5ba2d | 60 | alarm.start(); |
nbarnjak | 0:d33881c5ba2d | 61 | int x; |
nbarnjak | 0:d33881c5ba2d | 62 | while(alarm.read()<1 && debounce.read_ms()>200) { |
nbarnjak | 0:d33881c5ba2d | 63 | for(x=0; x<4; x++) { |
nbarnjak | 0:d33881c5ba2d | 64 | led1.flip(); |
nbarnjak | 0:d33881c5ba2d | 65 | led5.flip(); |
nbarnjak | 0:d33881c5ba2d | 66 | wait(0.25); |
nbarnjak | 0:d33881c5ba2d | 67 | alarm.reset(); |
nbarnjak | 0:d33881c5ba2d | 68 | alarm.start(); |
nbarnjak | 0:d33881c5ba2d | 69 | |
nbarnjak | 0:d33881c5ba2d | 70 | } |
nbarnjak | 0:d33881c5ba2d | 71 | } |
nbarnjak | 0:d33881c5ba2d | 72 | } |
nbarnjak | 0:d33881c5ba2d | 73 | } |
nbarnjak | 0:d33881c5ba2d | 74 | return 0; |
nbarnjak | 0:d33881c5ba2d | 75 | } |