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