Programmeringsgruppe 1
/
Alarmsystem20_02_2018
klokka 15:07
Fork of AlarmsystemDel1 by
main.cpp@5:045ef3068f21, 2018-01-30 (annotated)
- Committer:
- Banyrud
- Date:
- Tue Jan 30 10:41:49 2018 +0000
- Revision:
- 5:045ef3068f21
- Parent:
- 4:aa2cff91ff4f
- Child:
- 6:a3b97bf7902b
- Child:
- 7:25e0260ee887
rev5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andreped | 0:33bf28fd1ac6 | 1 | #include "mbed.h" |
andreped | 0:33bf28fd1ac6 | 2 | |
andreped | 3:26a7b2c4bed1 | 3 | #define Feil 0<1 |
andreped | 3:26a7b2c4bed1 | 4 | #define Tilstand1 2.5<2.7 |
andreped | 3:26a7b2c4bed1 | 5 | #define Tilstand2 2.1<2.3 |
andreped | 3:26a7b2c4bed1 | 6 | #define Tilstand3 3.3 |
andreped | 3:26a7b2c4bed1 | 7 | #define Normaldrift 1.8<2.0 |
Banyrud | 5:045ef3068f21 | 8 | DigitalOut myled2(LED2); |
andreped | 4:aa2cff91ff4f | 9 | Serial pc(USBTX, USBRX); |
andreped | 0:33bf28fd1ac6 | 10 | DigitalOut Driftslys(LED1); |
andreped | 1:6917ec4f5e6d | 11 | BusOut AlarmUtganger1(p21, p22, p23, p24); |
andreped | 1:6917ec4f5e6d | 12 | BusOut AlarmUtganger2(p25, p26, p27, p28); |
andreped | 0:33bf28fd1ac6 | 13 | DigitalIn Servicebryter(p20); |
Banyrud | 5:045ef3068f21 | 14 | AnalogIn _Sone1(p15); float Sone1 = _Sone1 * 3.3; |
Banyrud | 5:045ef3068f21 | 15 | AnalogIn _Sone2(p16); float Sone2 = _Sone2 * 3.3; |
Banyrud | 5:045ef3068f21 | 16 | AnalogIn _Sone3(p17); float Sone3 = _Sone3 * 3.3; |
Banyrud | 5:045ef3068f21 | 17 | AnalogIn _Sone4(p19); float Sone4 = _Sone4 * 3.3; |
andreped | 1:6917ec4f5e6d | 18 | |
andreped | 1:6917ec4f5e6d | 19 | |
andreped | 1:6917ec4f5e6d | 20 | Ticker AlarmBlink; //10Hz blinking for alarmfunksjon på lys og telling |
andreped | 1:6917ec4f5e6d | 21 | int Tid = 0; |
andreped | 1:6917ec4f5e6d | 22 | volatile int sysclock = 0; |
andreped | 0:33bf28fd1ac6 | 23 | |
andreped | 4:aa2cff91ff4f | 24 | int Utganger1 = AlarmUtganger1; |
andreped | 4:aa2cff91ff4f | 25 | int Utganger2 = AlarmUtganger2; |
andreped | 4:aa2cff91ff4f | 26 | int Bryter = Servicebryter; |
andreped | 4:aa2cff91ff4f | 27 | int Door1_1 = 0, Door1_2 = 0, Door2_1 = 0, Door2_2 = 0, Door3_1 = 0, Door3_2 = 0, Door4_1 = 0, Door4_2 = 0; |
andreped | 4:aa2cff91ff4f | 28 | float ArrSone[4] = {Sone1, Sone2, Sone3, Sone4}; |
andreped | 4:aa2cff91ff4f | 29 | int DoorOne[4] = { Door1_1, Door2_1, Door3_1, Door4_1 }; |
andreped | 4:aa2cff91ff4f | 30 | int DoorTwo[4] = { Door1_2, Door2_2, Door3_2, Door4_2 }; |
andreped | 1:6917ec4f5e6d | 31 | |
andreped | 1:6917ec4f5e6d | 32 | enum {_Feil, _Tilstand1, _Tilstand2, _Tilstand3, _NormalDrift} Tilstand; // Tilstand1 = Bryter1 i Sonen valgt, Tilstand2 = Bryter2 i sonen valgt, Tilstand3 = bryter 1 og 2 i sonen valgt, Normaldrift = alt er optimalt. |
andreped | 1:6917ec4f5e6d | 33 | int Tilstandssjekk(); |
andreped | 1:6917ec4f5e6d | 34 | void AlarmBlink_Start(void); |
andreped | 1:6917ec4f5e6d | 35 | volatile int Klokke = 0; |
andreped | 1:6917ec4f5e6d | 36 | |
andreped | 1:6917ec4f5e6d | 37 | int main() |
andreped | 1:6917ec4f5e6d | 38 | { |
andreped | 1:6917ec4f5e6d | 39 | AlarmBlink.attach(&AlarmBlink_Start, 0.05); |
andreped | 1:6917ec4f5e6d | 40 | |
andreped | 1:6917ec4f5e6d | 41 | while(1) { |
andreped | 1:6917ec4f5e6d | 42 | if(Servicebryter == 1) { |
andreped | 1:6917ec4f5e6d | 43 | Utganger1 = 0; |
andreped | 1:6917ec4f5e6d | 44 | Utganger2 = 0; |
andreped | 1:6917ec4f5e6d | 45 | } |
andreped | 1:6917ec4f5e6d | 46 | Tilstandssjekk(); |
andreped | 4:aa2cff91ff4f | 47 | float volt = Sone1; |
andreped | 4:aa2cff91ff4f | 48 | pc.printf("%f\n", volt); |
Banyrud | 5:045ef3068f21 | 49 | wait(1.0); |
Banyrud | 5:045ef3068f21 | 50 | //while(sysclock == 1); |
Banyrud | 5:045ef3068f21 | 51 | //while(sysclock == 0); |
andreped | 1:6917ec4f5e6d | 52 | Tid++; |
andreped | 0:33bf28fd1ac6 | 53 | |
andreped | 0:33bf28fd1ac6 | 54 | |
andreped | 0:33bf28fd1ac6 | 55 | } |
andreped | 0:33bf28fd1ac6 | 56 | } |
andreped | 1:6917ec4f5e6d | 57 | |
andreped | 1:6917ec4f5e6d | 58 | int Tilstandssjekk() |
andreped | 1:6917ec4f5e6d | 59 | { |
andreped | 1:6917ec4f5e6d | 60 | int i = 0; |
andreped | 1:6917ec4f5e6d | 61 | for(i = 0; i < 3; i++) { |
andreped | 1:6917ec4f5e6d | 62 | if(ArrSone[i] == Tilstand1) { |
andreped | 1:6917ec4f5e6d | 63 | AlarmBlink_Start(); |
andreped | 3:26a7b2c4bed1 | 64 | DoorOne[i] = AlarmUtganger1; |
andreped | 1:6917ec4f5e6d | 65 | } |
andreped | 1:6917ec4f5e6d | 66 | if(Tilstand2 == ArrSone[i]) { |
andreped | 1:6917ec4f5e6d | 67 | AlarmBlink_Start(); |
andreped | 3:26a7b2c4bed1 | 68 | DoorTwo[i] = AlarmUtganger2; |
andreped | 1:6917ec4f5e6d | 69 | } |
andreped | 1:6917ec4f5e6d | 70 | if(Tilstand3 == ArrSone[i]) { |
andreped | 1:6917ec4f5e6d | 71 | AlarmBlink_Start(); |
andreped | 3:26a7b2c4bed1 | 72 | DoorOne[i] = AlarmUtganger1; |
andreped | 3:26a7b2c4bed1 | 73 | DoorTwo[i] = AlarmUtganger2; |
andreped | 1:6917ec4f5e6d | 74 | } |
andreped | 1:6917ec4f5e6d | 75 | if(Feil == ArrSone[i]) { |
andreped | 1:6917ec4f5e6d | 76 | AlarmBlink_Start(); |
andreped | 1:6917ec4f5e6d | 77 | } |
andreped | 1:6917ec4f5e6d | 78 | if(Normaldrift == ArrSone[i]) { |
andreped | 1:6917ec4f5e6d | 79 | Driftslys = 1; |
andreped | 3:26a7b2c4bed1 | 80 | DoorOne[i] = AlarmUtganger1 - DoorOne[i]; |
Banyrud | 5:045ef3068f21 | 81 | myled2 = 1; |
andreped | 1:6917ec4f5e6d | 82 | } |
andreped | 1:6917ec4f5e6d | 83 | if(i < 0 ) { |
andreped | 3:26a7b2c4bed1 | 84 | DoorOne[i] = AlarmUtganger1 + DoorOne[i]; |
andreped | 3:26a7b2c4bed1 | 85 | DoorTwo[i] = AlarmUtganger2 - DoorTwo[i]; |
andreped | 1:6917ec4f5e6d | 86 | } |
andreped | 1:6917ec4f5e6d | 87 | if(i < 0 ) { |
andreped | 3:26a7b2c4bed1 | 88 | DoorOne[i] = AlarmUtganger2 + DoorTwo[i]; |
andreped | 1:6917ec4f5e6d | 89 | } |
andreped | 1:6917ec4f5e6d | 90 | } |
Banyrud | 5:045ef3068f21 | 91 | return 0; |
andreped | 1:6917ec4f5e6d | 92 | } |
andreped | 1:6917ec4f5e6d | 93 | |
andreped | 1:6917ec4f5e6d | 94 | void AlarmBlink_Start(void) |
andreped | 1:6917ec4f5e6d | 95 | { |
andreped | 1:6917ec4f5e6d | 96 | sysclock = !sysclock; |
andreped | 1:6917ec4f5e6d | 97 | Driftslys = 1; |
andreped | 1:6917ec4f5e6d | 98 | if(Normaldrift == 1) { |
andreped | 1:6917ec4f5e6d | 99 | sysclock = 1; |
andreped | 1:6917ec4f5e6d | 100 | } |
andreped | 1:6917ec4f5e6d | 101 | } |