![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
06.03.2018
Fork of Alarmsystem_med_matrix_log_funker_ikke by
main.cpp
- Committer:
- andreped
- Date:
- 2018-02-01
- Revision:
- 8:bdb8bd12d4f4
- Parent:
- 7:25e0260ee887
- Child:
- 9:e9c4715e06ca
File content as of revision 8:bdb8bd12d4f4:
#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 = _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 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_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); // 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) { AlarmUtganger1 = 0; AlarmUtganger2 = 0; } Tilstandssjekk(); float volt = Sone1*3.3; pc.printf("%f\n", volt); wait(1.0); //while(sysclock == 1); //while(sysclock == 0); Tid++; } } int Tilstandssjekk() { int i = 0; for(i = 0; i < 3; i++) { if(filled_arrSone[i] == Tilstand1) { pc.printf("I tilstand 1\n"); filled_arrDoorOne[i] = AlarmUtganger1; AlarmBlink_Start(); } if(Tilstand2 == filled_arrSone[i]) { pc.printf("I tilstand 2\n"); filled_arrDoorTwo[i] = AlarmUtganger2; AlarmBlink_Start(); } if(Tilstand3 == filled_arrSone[i]) { pc.printf("I tilstand 3\n"); filled_arrDoorOne[i] = AlarmUtganger1; filled_arrDoorTwo[i] = AlarmUtganger2; AlarmBlink_Start(); } if(Feil == filled_arrSone[i]) { pc.printf("I tilstand feil\n"); AlarmBlink_Start(); } if(Normaldrift == filled_arrSone[i]) { Driftslys = 1; filled_arrDoorOne[i] = AlarmUtganger1 - filled_arrDoorOne[i]; pc.printf("I tilstand normaldrift\n"); } if(i < 0 ) { filled_arrDoorOne[i] = AlarmUtganger1 + filled_arrDoorOne[i]; filled_arrDoorTwo[i] = AlarmUtganger2 - filled_arrDoorTwo[i]; } if(i < 0 ) { filled_arrDoorOne[i] = AlarmUtganger2 + filled_arrDoorTwo[i]; } } return 0; } void AlarmBlink_Start(void) { sysclock = !sysclock; Driftslys = 1; } void fill_arrSone (float Sone1, float Sone2, float Sone3, float Sone4){ filled_arrSone[4] = {Sone1, Sone2, Sone3, 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; }