![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
06.03.2018
Fork of Alarmsystem_med_matrix_log_funker_ikke by
Diff: main.cpp
- Revision:
- 8:bdb8bd12d4f4
- Parent:
- 7:25e0260ee887
- Child:
- 9:e9c4715e06ca
--- a/main.cpp Thu Feb 01 09:07:51 2018 +0000 +++ b/main.cpp Thu Feb 01 21:47:19 2018 +0000 @@ -1,46 +1,46 @@ #include "mbed.h" +#include <vector> #define Feil 0<1 #define Tilstand1 2.5<2.7 #define Tilstand2 2.1<2.3 #define Tilstand3 3.3 #define Normaldrift 1.8<2.0 + +vector<DigitalOut> navn; navn.push_back( *(new DigitalOut( p17 )) ); DigitalOut myled2(LED2); Serial pc(USBTX, USBRX); DigitalOut Driftslys(LED1); BusOut AlarmUtganger1(p21, p22, p23, p24); BusOut AlarmUtganger2(p25, p26, p27, p28); DigitalIn Servicebryter(p20); -AnalogIn _Sone1(p15); float Sone1; -AnalogIn _Sone2(p16); float Sone2; -AnalogIn _Sone3(p17); float Sone3; -AnalogIn _Sone4(p19); float Sone4; +AnalogIn _Sone1(p15); float Sone1 = _Sone1 * 3.3; +AnalogIn _Sone2(p16); float Sone2 = _Sone2 * 3.3; +AnalogIn _Sone3(p17); float Sone3 = _Sone3 * 3.3; +AnalogIn _Sone4(p19); float Sone4 = _Sone4 * 3.3; + Ticker AlarmBlink; //10Hz blinking for alarmfunksjon på lys og telling int Tid = 0; volatile int sysclock = 0; - -int Utganger1 = AlarmUtganger1; -int Utganger2 = AlarmUtganger2; -int Bryter = Servicebryter; -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; +int Door1_1, Door1_2, Door2_1, Door2_2, Door3_1, Door3_2, Door4_1, Door4_2; void fill_arrSone (float Sone1,float Sone2,float Sone3,float Sone4); -float filled_arr[10]; -int DoorOne[4] = { Door1_1, Door2_1, Door3_1, Door4_1 }; -int DoorTwo[4] = { Door1_2, Door2_2, Door3_2, Door4_2 }; - -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. +float filled_arrSone[4]; +void fill_arrDoorOne(int Door1_1,int Door2_1,int Door3_1,int Door4_1); +int filled_arrDoorOne[4]; +void fill_arrDoorTwo(int Door1_2,int Door2_2,int Door3_2,int Door4_2); +int filled_arrDoorTwo[4]; int Tilstandssjekk(); void AlarmBlink_Start(void); -volatile int Klokke = 0; - +// ubrukelig nå // int Bryter = Servicebryter; +// ubrukelig nå // volatile int Klokke = 0; +// ubrukelig nå // 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. int main() { AlarmBlink.attach(&AlarmBlink_Start, 0.05); - while(1) { if(Servicebryter == 1) { - Utganger1 = 0; - Utganger2 = 0; + AlarmUtganger1 = 0; + AlarmUtganger2 = 0; } Tilstandssjekk(); float volt = Sone1*3.3; @@ -56,37 +56,37 @@ { int i = 0; for(i = 0; i < 3; i++) { - if(filled_arr[i] == Tilstand1) { + if(filled_arrSone[i] == Tilstand1) { pc.printf("I tilstand 1\n"); + filled_arrDoorOne[i] = AlarmUtganger1; AlarmBlink_Start(); - DoorOne[i] = AlarmUtganger1; } - if(Tilstand2 == filled_arr[i]) { + if(Tilstand2 == filled_arrSone[i]) { pc.printf("I tilstand 2\n"); + filled_arrDoorTwo[i] = AlarmUtganger2; AlarmBlink_Start(); - DoorTwo[i] = AlarmUtganger2; } - if(Tilstand3 == filled_arr[i]) { + if(Tilstand3 == filled_arrSone[i]) { pc.printf("I tilstand 3\n"); - AlarmBlink_Start(); - DoorOne[i] = AlarmUtganger1; - DoorTwo[i] = AlarmUtganger2; - } - if(Feil == filled_arr[i]) { + filled_arrDoorOne[i] = AlarmUtganger1; + filled_arrDoorTwo[i] = AlarmUtganger2; AlarmBlink_Start(); - pc.printf("I tilstand feil\n"); } - if(Normaldrift == filled_arr[i]) { + if(Feil == filled_arrSone[i]) { + pc.printf("I tilstand feil\n"); + AlarmBlink_Start(); + } + if(Normaldrift == filled_arrSone[i]) { Driftslys = 1; - DoorOne[i] = AlarmUtganger1 - DoorOne[i]; + filled_arrDoorOne[i] = AlarmUtganger1 - filled_arrDoorOne[i]; pc.printf("I tilstand normaldrift\n"); } if(i < 0 ) { - DoorOne[i] = AlarmUtganger1 + DoorOne[i]; - DoorTwo[i] = AlarmUtganger2 - DoorTwo[i]; + filled_arrDoorOne[i] = AlarmUtganger1 + filled_arrDoorOne[i]; + filled_arrDoorTwo[i] = AlarmUtganger2 - filled_arrDoorTwo[i]; } if(i < 0 ) { - DoorOne[i] = AlarmUtganger2 + DoorTwo[i]; + filled_arrDoorOne[i] = AlarmUtganger2 + filled_arrDoorTwo[i]; } } return 0; @@ -96,15 +96,20 @@ { sysclock = !sysclock; Driftslys = 1; - if(Normaldrift == 1) { - Driftslys = 1; - Utganger1 = 0; - Utganger2 = 0; - } +} +void fill_arrSone (float Sone1, float Sone2, float Sone3, float Sone4){ + filled_arrSone[4] = {Sone1, Sone2, Sone3, Sone4}; + } -void fill_arrSone =(float Sone1, float Sone2, float Sone3, float Sone4){ - filled_arr[1] = Sone1; - filled_arr[2] = Sone2; - filled_arr[3] = Sone3; - filled_arr[4] = Sone4; +void fill_arrDoorOne(int Door1_1,int Door2_1,int Door3_1,int Door4_1) { + filled_arrDoorOne[0] = Door1_1; + filled_arrDoorOne[1] = Door2_1; + filled_arrDoorOne[2] = Door3_1; + filled_arrDoorOne[3] = Door4_1; +} +void fill_arrDoorTwo(int Door1_2,int Door2_2,int Door3_2,int Door4_2) { + filled_arrDoorOne[0] = Door1_2; + filled_arrDoorOne[1] = Door2_2; + filled_arrDoorOne[2] = Door3_2; + filled_arrDoorOne[3] = Door4_2; } \ No newline at end of file