![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
06.03.2018
Fork of Alarmsystem_med_matrix_log_funker_ikke by
main.cpp@7:25e0260ee887, 2018-02-01 (annotated)
- Committer:
- Banyrud
- Date:
- Thu Feb 01 09:07:51 2018 +0000
- Revision:
- 7:25e0260ee887
- Parent:
- 5:045ef3068f21
- Child:
- 8:bdb8bd12d4f4
rev5/6
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 | 7:25e0260ee887 | 14 | AnalogIn _Sone1(p15); float Sone1; |
Banyrud | 7:25e0260ee887 | 15 | AnalogIn _Sone2(p16); float Sone2; |
Banyrud | 7:25e0260ee887 | 16 | AnalogIn _Sone3(p17); float Sone3; |
Banyrud | 7:25e0260ee887 | 17 | AnalogIn _Sone4(p19); float Sone4; |
andreped | 1:6917ec4f5e6d | 18 | Ticker AlarmBlink; //10Hz blinking for alarmfunksjon på lys og telling |
andreped | 1:6917ec4f5e6d | 19 | int Tid = 0; |
andreped | 1:6917ec4f5e6d | 20 | volatile int sysclock = 0; |
andreped | 0:33bf28fd1ac6 | 21 | |
andreped | 4:aa2cff91ff4f | 22 | int Utganger1 = AlarmUtganger1; |
andreped | 4:aa2cff91ff4f | 23 | int Utganger2 = AlarmUtganger2; |
andreped | 4:aa2cff91ff4f | 24 | int Bryter = Servicebryter; |
andreped | 4:aa2cff91ff4f | 25 | 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; |
Banyrud | 7:25e0260ee887 | 26 | void fill_arrSone (float Sone1,float Sone2,float Sone3,float Sone4); |
Banyrud | 7:25e0260ee887 | 27 | float filled_arr[10]; |
andreped | 4:aa2cff91ff4f | 28 | int DoorOne[4] = { Door1_1, Door2_1, Door3_1, Door4_1 }; |
andreped | 4:aa2cff91ff4f | 29 | int DoorTwo[4] = { Door1_2, Door2_2, Door3_2, Door4_2 }; |
andreped | 1:6917ec4f5e6d | 30 | |
andreped | 1:6917ec4f5e6d | 31 | 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 | 32 | int Tilstandssjekk(); |
andreped | 1:6917ec4f5e6d | 33 | void AlarmBlink_Start(void); |
andreped | 1:6917ec4f5e6d | 34 | volatile int Klokke = 0; |
andreped | 1:6917ec4f5e6d | 35 | |
andreped | 1:6917ec4f5e6d | 36 | int main() |
andreped | 1:6917ec4f5e6d | 37 | { |
andreped | 1:6917ec4f5e6d | 38 | AlarmBlink.attach(&AlarmBlink_Start, 0.05); |
andreped | 1:6917ec4f5e6d | 39 | |
andreped | 1:6917ec4f5e6d | 40 | while(1) { |
andreped | 1:6917ec4f5e6d | 41 | if(Servicebryter == 1) { |
andreped | 1:6917ec4f5e6d | 42 | Utganger1 = 0; |
andreped | 1:6917ec4f5e6d | 43 | Utganger2 = 0; |
andreped | 1:6917ec4f5e6d | 44 | } |
andreped | 1:6917ec4f5e6d | 45 | Tilstandssjekk(); |
Banyrud | 7:25e0260ee887 | 46 | float volt = Sone1*3.3; |
andreped | 4:aa2cff91ff4f | 47 | pc.printf("%f\n", volt); |
Banyrud | 5:045ef3068f21 | 48 | wait(1.0); |
Banyrud | 5:045ef3068f21 | 49 | //while(sysclock == 1); |
Banyrud | 5:045ef3068f21 | 50 | //while(sysclock == 0); |
andreped | 1:6917ec4f5e6d | 51 | Tid++; |
andreped | 0:33bf28fd1ac6 | 52 | } |
andreped | 0:33bf28fd1ac6 | 53 | } |
andreped | 1:6917ec4f5e6d | 54 | |
andreped | 1:6917ec4f5e6d | 55 | int Tilstandssjekk() |
andreped | 1:6917ec4f5e6d | 56 | { |
andreped | 1:6917ec4f5e6d | 57 | int i = 0; |
andreped | 1:6917ec4f5e6d | 58 | for(i = 0; i < 3; i++) { |
Banyrud | 7:25e0260ee887 | 59 | if(filled_arr[i] == Tilstand1) { |
Banyrud | 7:25e0260ee887 | 60 | pc.printf("I tilstand 1\n"); |
andreped | 1:6917ec4f5e6d | 61 | AlarmBlink_Start(); |
andreped | 3:26a7b2c4bed1 | 62 | DoorOne[i] = AlarmUtganger1; |
andreped | 1:6917ec4f5e6d | 63 | } |
Banyrud | 7:25e0260ee887 | 64 | if(Tilstand2 == filled_arr[i]) { |
Banyrud | 7:25e0260ee887 | 65 | pc.printf("I tilstand 2\n"); |
andreped | 1:6917ec4f5e6d | 66 | AlarmBlink_Start(); |
andreped | 3:26a7b2c4bed1 | 67 | DoorTwo[i] = AlarmUtganger2; |
andreped | 1:6917ec4f5e6d | 68 | } |
Banyrud | 7:25e0260ee887 | 69 | if(Tilstand3 == filled_arr[i]) { |
Banyrud | 7:25e0260ee887 | 70 | pc.printf("I tilstand 3\n"); |
andreped | 1:6917ec4f5e6d | 71 | AlarmBlink_Start(); |
andreped | 3:26a7b2c4bed1 | 72 | DoorOne[i] = AlarmUtganger1; |
andreped | 3:26a7b2c4bed1 | 73 | DoorTwo[i] = AlarmUtganger2; |
andreped | 1:6917ec4f5e6d | 74 | } |
Banyrud | 7:25e0260ee887 | 75 | if(Feil == filled_arr[i]) { |
andreped | 1:6917ec4f5e6d | 76 | AlarmBlink_Start(); |
Banyrud | 7:25e0260ee887 | 77 | pc.printf("I tilstand feil\n"); |
andreped | 1:6917ec4f5e6d | 78 | } |
Banyrud | 7:25e0260ee887 | 79 | if(Normaldrift == filled_arr[i]) { |
andreped | 1:6917ec4f5e6d | 80 | Driftslys = 1; |
andreped | 3:26a7b2c4bed1 | 81 | DoorOne[i] = AlarmUtganger1 - DoorOne[i]; |
Banyrud | 7:25e0260ee887 | 82 | pc.printf("I tilstand normaldrift\n"); |
andreped | 1:6917ec4f5e6d | 83 | } |
andreped | 1:6917ec4f5e6d | 84 | if(i < 0 ) { |
andreped | 3:26a7b2c4bed1 | 85 | DoorOne[i] = AlarmUtganger1 + DoorOne[i]; |
andreped | 3:26a7b2c4bed1 | 86 | DoorTwo[i] = AlarmUtganger2 - DoorTwo[i]; |
andreped | 1:6917ec4f5e6d | 87 | } |
andreped | 1:6917ec4f5e6d | 88 | if(i < 0 ) { |
andreped | 3:26a7b2c4bed1 | 89 | DoorOne[i] = AlarmUtganger2 + DoorTwo[i]; |
andreped | 1:6917ec4f5e6d | 90 | } |
andreped | 1:6917ec4f5e6d | 91 | } |
Banyrud | 5:045ef3068f21 | 92 | return 0; |
andreped | 1:6917ec4f5e6d | 93 | } |
andreped | 1:6917ec4f5e6d | 94 | |
andreped | 1:6917ec4f5e6d | 95 | void AlarmBlink_Start(void) |
andreped | 1:6917ec4f5e6d | 96 | { |
andreped | 1:6917ec4f5e6d | 97 | sysclock = !sysclock; |
andreped | 1:6917ec4f5e6d | 98 | Driftslys = 1; |
andreped | 1:6917ec4f5e6d | 99 | if(Normaldrift == 1) { |
Banyrud | 7:25e0260ee887 | 100 | Driftslys = 1; |
Banyrud | 7:25e0260ee887 | 101 | Utganger1 = 0; |
Banyrud | 7:25e0260ee887 | 102 | Utganger2 = 0; |
andreped | 1:6917ec4f5e6d | 103 | } |
Banyrud | 7:25e0260ee887 | 104 | } |
Banyrud | 7:25e0260ee887 | 105 | void fill_arrSone =(float Sone1, float Sone2, float Sone3, float Sone4){ |
Banyrud | 7:25e0260ee887 | 106 | filled_arr[1] = Sone1; |
Banyrud | 7:25e0260ee887 | 107 | filled_arr[2] = Sone2; |
Banyrud | 7:25e0260ee887 | 108 | filled_arr[3] = Sone3; |
Banyrud | 7:25e0260ee887 | 109 | filled_arr[4] = Sone4; |
andreped | 1:6917ec4f5e6d | 110 | } |