Programmeringsgruppe 1
/
Alarmsystem20_02_2018
klokka 15:07
Fork of AlarmsystemDel1 by
main.cpp@3:26a7b2c4bed1, 2018-01-30 (annotated)
- Committer:
- andreped
- Date:
- Tue Jan 30 10:00:04 2018 +0000
- Revision:
- 3:26a7b2c4bed1
- Parent:
- 2:cef96d07d3cd
- Child:
- 4:aa2cff91ff4f
004
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 |
andreped | 0:33bf28fd1ac6 | 8 | |
andreped | 0:33bf28fd1ac6 | 9 | DigitalOut Driftslys(LED1); |
andreped | 1:6917ec4f5e6d | 10 | BusOut AlarmUtganger1(p21, p22, p23, p24); |
andreped | 1:6917ec4f5e6d | 11 | BusOut AlarmUtganger2(p25, p26, p27, p28); |
andreped | 0:33bf28fd1ac6 | 12 | DigitalIn Servicebryter(p20); |
andreped | 1:6917ec4f5e6d | 13 | DigitalIn _Sone1(p15); |
andreped | 1:6917ec4f5e6d | 14 | DigitalIn _Sone2(p16); |
andreped | 1:6917ec4f5e6d | 15 | DigitalIn _Sone3(p17); |
andreped | 1:6917ec4f5e6d | 16 | DigitalIn _Sone4(p19); |
andreped | 1:6917ec4f5e6d | 17 | |
andreped | 1:6917ec4f5e6d | 18 | |
andreped | 1:6917ec4f5e6d | 19 | Ticker AlarmBlink; //10Hz blinking for alarmfunksjon på lys og telling |
andreped | 1:6917ec4f5e6d | 20 | int Tid = 0; |
andreped | 1:6917ec4f5e6d | 21 | volatile int sysclock = 0; |
andreped | 0:33bf28fd1ac6 | 22 | |
andreped | 1:6917ec4f5e6d | 23 | volatile int Utganger1 = AlarmUtganger1; |
andreped | 1:6917ec4f5e6d | 24 | volatile int Utganger2 = AlarmUtganger2; |
andreped | 1:6917ec4f5e6d | 25 | volatile int Bryter = Servicebryter; |
andreped | 1:6917ec4f5e6d | 26 | volatile 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 | 2:cef96d07d3cd | 27 | volatile float Sone1 = _Sone1 * 3.3; |
andreped | 2:cef96d07d3cd | 28 | volatile float Sone2 = _Sone2 * 3.3; |
andreped | 2:cef96d07d3cd | 29 | volatile float Sone3 = _Sone3 * 3.3; |
andreped | 2:cef96d07d3cd | 30 | volatile float Sone4 = _Sone4 * 3.3; |
andreped | 1:6917ec4f5e6d | 31 | volatile int ArrSone[4] = {Sone1, Sone2, Sone3, Sone4}; |
andreped | 1:6917ec4f5e6d | 32 | volatile int DoorOne[4] = { Door1_1, Door2_1, Door3_1, Door4_1 }; |
andreped | 1:6917ec4f5e6d | 33 | volatile int DoorTwo[4] = { Door1_2, Door2_2, Door3_2, Door4_2 }; |
andreped | 1:6917ec4f5e6d | 34 | |
andreped | 1:6917ec4f5e6d | 35 | 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 | 36 | int Tilstandssjekk(); |
andreped | 1:6917ec4f5e6d | 37 | void AlarmBlink_Start(void); |
andreped | 1:6917ec4f5e6d | 38 | volatile int Klokke = 0; |
andreped | 1:6917ec4f5e6d | 39 | |
andreped | 1:6917ec4f5e6d | 40 | int main() |
andreped | 1:6917ec4f5e6d | 41 | { |
andreped | 1:6917ec4f5e6d | 42 | AlarmBlink.attach(&AlarmBlink_Start, 0.05); |
andreped | 1:6917ec4f5e6d | 43 | |
andreped | 1:6917ec4f5e6d | 44 | while(1) { |
andreped | 1:6917ec4f5e6d | 45 | if(Servicebryter == 1) { |
andreped | 1:6917ec4f5e6d | 46 | Utganger1 = 0; |
andreped | 1:6917ec4f5e6d | 47 | Utganger2 = 0; |
andreped | 1:6917ec4f5e6d | 48 | } |
andreped | 1:6917ec4f5e6d | 49 | Tilstandssjekk(); |
andreped | 1:6917ec4f5e6d | 50 | while(sysclock == 1); |
andreped | 1:6917ec4f5e6d | 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 | static float Sone1 = Sone1 * 3.3; |
andreped | 1:6917ec4f5e6d | 61 | static float Sone2 = Sone2 * 3.3; |
andreped | 1:6917ec4f5e6d | 62 | static float Sone3 = Sone3 * 3.3; |
andreped | 1:6917ec4f5e6d | 63 | static float Sone4 = Sone4 * 3.3; |
andreped | 1:6917ec4f5e6d | 64 | int i = 0; |
andreped | 1:6917ec4f5e6d | 65 | ArrSone[i]; |
andreped | 1:6917ec4f5e6d | 66 | DoorOne[i]; |
andreped | 1:6917ec4f5e6d | 67 | DoorTwo[i]; |
andreped | 1:6917ec4f5e6d | 68 | static int Utganger1; |
andreped | 1:6917ec4f5e6d | 69 | static int Utganger2; |
andreped | 1:6917ec4f5e6d | 70 | |
andreped | 1:6917ec4f5e6d | 71 | for(i = 0; i < 3; i++) { |
andreped | 1:6917ec4f5e6d | 72 | if(ArrSone[i] == Tilstand1) { |
andreped | 1:6917ec4f5e6d | 73 | AlarmBlink_Start(); |
andreped | 3:26a7b2c4bed1 | 74 | DoorOne[i] = AlarmUtganger1; |
andreped | 1:6917ec4f5e6d | 75 | } |
andreped | 1:6917ec4f5e6d | 76 | if(Tilstand2 == ArrSone[i]) { |
andreped | 1:6917ec4f5e6d | 77 | AlarmBlink_Start(); |
andreped | 3:26a7b2c4bed1 | 78 | DoorTwo[i] = AlarmUtganger2; |
andreped | 1:6917ec4f5e6d | 79 | } |
andreped | 1:6917ec4f5e6d | 80 | if(Tilstand3 == ArrSone[i]) { |
andreped | 1:6917ec4f5e6d | 81 | AlarmBlink_Start(); |
andreped | 3:26a7b2c4bed1 | 82 | DoorOne[i] = AlarmUtganger1; |
andreped | 3:26a7b2c4bed1 | 83 | DoorTwo[i] = AlarmUtganger2; |
andreped | 1:6917ec4f5e6d | 84 | } |
andreped | 1:6917ec4f5e6d | 85 | if(Feil == ArrSone[i]) { |
andreped | 1:6917ec4f5e6d | 86 | AlarmBlink_Start(); |
andreped | 1:6917ec4f5e6d | 87 | } |
andreped | 1:6917ec4f5e6d | 88 | if(Normaldrift == ArrSone[i]) { |
andreped | 1:6917ec4f5e6d | 89 | Driftslys = 1; |
andreped | 3:26a7b2c4bed1 | 90 | DoorOne[i] = AlarmUtganger1 - DoorOne[i]; |
andreped | 1:6917ec4f5e6d | 91 | } |
andreped | 1:6917ec4f5e6d | 92 | if(i < 0 ) { |
andreped | 3:26a7b2c4bed1 | 93 | DoorOne[i] = AlarmUtganger1 + DoorOne[i]; |
andreped | 3:26a7b2c4bed1 | 94 | DoorTwo[i] = AlarmUtganger2 - DoorTwo[i]; |
andreped | 1:6917ec4f5e6d | 95 | } |
andreped | 1:6917ec4f5e6d | 96 | if(i < 0 ) { |
andreped | 3:26a7b2c4bed1 | 97 | DoorOne[i] = AlarmUtganger2 + DoorTwo[i]; |
andreped | 1:6917ec4f5e6d | 98 | } |
andreped | 1:6917ec4f5e6d | 99 | } |
andreped | 1:6917ec4f5e6d | 100 | return ArrSone[i], DoorOne[i], DoorTwo[i]; |
andreped | 1:6917ec4f5e6d | 101 | } |
andreped | 1:6917ec4f5e6d | 102 | |
andreped | 1:6917ec4f5e6d | 103 | void AlarmBlink_Start(void) |
andreped | 1:6917ec4f5e6d | 104 | { |
andreped | 1:6917ec4f5e6d | 105 | sysclock = !sysclock; |
andreped | 1:6917ec4f5e6d | 106 | Driftslys = 1; |
andreped | 1:6917ec4f5e6d | 107 | if(Normaldrift == 1) { |
andreped | 1:6917ec4f5e6d | 108 | sysclock = 1; |
andreped | 1:6917ec4f5e6d | 109 | } |
andreped | 1:6917ec4f5e6d | 110 | } |