Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Alarmsystem_log_funksjon_funker_ikke by
main.cpp@8:bdb8bd12d4f4, 2018-02-01 (annotated)
- Committer:
- andreped
- Date:
- Thu Feb 01 21:47:19 2018 +0000
- Revision:
- 8:bdb8bd12d4f4
- Parent:
- 7:25e0260ee887
- Child:
- 9:e9c4715e06ca
008;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andreped | 0:33bf28fd1ac6 | 1 | #include "mbed.h" |
| andreped | 8:bdb8bd12d4f4 | 2 | #include <vector> |
| andreped | 0:33bf28fd1ac6 | 3 | |
| andreped | 3:26a7b2c4bed1 | 4 | #define Feil 0<1 |
| andreped | 3:26a7b2c4bed1 | 5 | #define Tilstand1 2.5<2.7 |
| andreped | 3:26a7b2c4bed1 | 6 | #define Tilstand2 2.1<2.3 |
| andreped | 3:26a7b2c4bed1 | 7 | #define Tilstand3 3.3 |
| andreped | 3:26a7b2c4bed1 | 8 | #define Normaldrift 1.8<2.0 |
| andreped | 8:bdb8bd12d4f4 | 9 | |
| andreped | 8:bdb8bd12d4f4 | 10 | vector<DigitalOut> navn; navn.push_back( *(new DigitalOut( p17 )) ); |
| Banyrud | 5:045ef3068f21 | 11 | DigitalOut myled2(LED2); |
| andreped | 4:aa2cff91ff4f | 12 | Serial pc(USBTX, USBRX); |
| andreped | 0:33bf28fd1ac6 | 13 | DigitalOut Driftslys(LED1); |
| andreped | 1:6917ec4f5e6d | 14 | BusOut AlarmUtganger1(p21, p22, p23, p24); |
| andreped | 1:6917ec4f5e6d | 15 | BusOut AlarmUtganger2(p25, p26, p27, p28); |
| andreped | 0:33bf28fd1ac6 | 16 | DigitalIn Servicebryter(p20); |
| andreped | 8:bdb8bd12d4f4 | 17 | AnalogIn _Sone1(p15); float Sone1 = _Sone1 * 3.3; |
| andreped | 8:bdb8bd12d4f4 | 18 | AnalogIn _Sone2(p16); float Sone2 = _Sone2 * 3.3; |
| andreped | 8:bdb8bd12d4f4 | 19 | AnalogIn _Sone3(p17); float Sone3 = _Sone3 * 3.3; |
| andreped | 8:bdb8bd12d4f4 | 20 | AnalogIn _Sone4(p19); float Sone4 = _Sone4 * 3.3; |
| andreped | 8:bdb8bd12d4f4 | 21 | |
| andreped | 1:6917ec4f5e6d | 22 | Ticker AlarmBlink; //10Hz blinking for alarmfunksjon på lys og telling |
| andreped | 1:6917ec4f5e6d | 23 | int Tid = 0; |
| andreped | 1:6917ec4f5e6d | 24 | volatile int sysclock = 0; |
| andreped | 8:bdb8bd12d4f4 | 25 | int Door1_1, Door1_2, Door2_1, Door2_2, Door3_1, Door3_2, Door4_1, Door4_2; |
| Banyrud | 7:25e0260ee887 | 26 | void fill_arrSone (float Sone1,float Sone2,float Sone3,float Sone4); |
| andreped | 8:bdb8bd12d4f4 | 27 | float filled_arrSone[4]; |
| andreped | 8:bdb8bd12d4f4 | 28 | void fill_arrDoorOne(int Door1_1,int Door2_1,int Door3_1,int Door4_1); |
| andreped | 8:bdb8bd12d4f4 | 29 | int filled_arrDoorOne[4]; |
| andreped | 8:bdb8bd12d4f4 | 30 | void fill_arrDoorTwo(int Door1_2,int Door2_2,int Door3_2,int Door4_2); |
| andreped | 8:bdb8bd12d4f4 | 31 | int filled_arrDoorTwo[4]; |
| andreped | 1:6917ec4f5e6d | 32 | int Tilstandssjekk(); |
| andreped | 1:6917ec4f5e6d | 33 | void AlarmBlink_Start(void); |
| andreped | 8:bdb8bd12d4f4 | 34 | // ubrukelig nå // int Bryter = Servicebryter; |
| andreped | 8:bdb8bd12d4f4 | 35 | // ubrukelig nå // volatile int Klokke = 0; |
| andreped | 8:bdb8bd12d4f4 | 36 | // 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. |
| andreped | 1:6917ec4f5e6d | 37 | int main() |
| andreped | 1:6917ec4f5e6d | 38 | { |
| andreped | 1:6917ec4f5e6d | 39 | AlarmBlink.attach(&AlarmBlink_Start, 0.05); |
| andreped | 1:6917ec4f5e6d | 40 | while(1) { |
| andreped | 1:6917ec4f5e6d | 41 | if(Servicebryter == 1) { |
| andreped | 8:bdb8bd12d4f4 | 42 | AlarmUtganger1 = 0; |
| andreped | 8:bdb8bd12d4f4 | 43 | AlarmUtganger2 = 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++) { |
| andreped | 8:bdb8bd12d4f4 | 59 | if(filled_arrSone[i] == Tilstand1) { |
| Banyrud | 7:25e0260ee887 | 60 | pc.printf("I tilstand 1\n"); |
| andreped | 8:bdb8bd12d4f4 | 61 | filled_arrDoorOne[i] = AlarmUtganger1; |
| andreped | 1:6917ec4f5e6d | 62 | AlarmBlink_Start(); |
| andreped | 1:6917ec4f5e6d | 63 | } |
| andreped | 8:bdb8bd12d4f4 | 64 | if(Tilstand2 == filled_arrSone[i]) { |
| Banyrud | 7:25e0260ee887 | 65 | pc.printf("I tilstand 2\n"); |
| andreped | 8:bdb8bd12d4f4 | 66 | filled_arrDoorTwo[i] = AlarmUtganger2; |
| andreped | 1:6917ec4f5e6d | 67 | AlarmBlink_Start(); |
| andreped | 1:6917ec4f5e6d | 68 | } |
| andreped | 8:bdb8bd12d4f4 | 69 | if(Tilstand3 == filled_arrSone[i]) { |
| Banyrud | 7:25e0260ee887 | 70 | pc.printf("I tilstand 3\n"); |
| andreped | 8:bdb8bd12d4f4 | 71 | filled_arrDoorOne[i] = AlarmUtganger1; |
| andreped | 8:bdb8bd12d4f4 | 72 | filled_arrDoorTwo[i] = AlarmUtganger2; |
| andreped | 1:6917ec4f5e6d | 73 | AlarmBlink_Start(); |
| andreped | 1:6917ec4f5e6d | 74 | } |
| andreped | 8:bdb8bd12d4f4 | 75 | if(Feil == filled_arrSone[i]) { |
| andreped | 8:bdb8bd12d4f4 | 76 | pc.printf("I tilstand feil\n"); |
| andreped | 8:bdb8bd12d4f4 | 77 | AlarmBlink_Start(); |
| andreped | 8:bdb8bd12d4f4 | 78 | } |
| andreped | 8:bdb8bd12d4f4 | 79 | if(Normaldrift == filled_arrSone[i]) { |
| andreped | 1:6917ec4f5e6d | 80 | Driftslys = 1; |
| andreped | 8:bdb8bd12d4f4 | 81 | filled_arrDoorOne[i] = AlarmUtganger1 - filled_arrDoorOne[i]; |
| Banyrud | 7:25e0260ee887 | 82 | pc.printf("I tilstand normaldrift\n"); |
| andreped | 1:6917ec4f5e6d | 83 | } |
| andreped | 1:6917ec4f5e6d | 84 | if(i < 0 ) { |
| andreped | 8:bdb8bd12d4f4 | 85 | filled_arrDoorOne[i] = AlarmUtganger1 + filled_arrDoorOne[i]; |
| andreped | 8:bdb8bd12d4f4 | 86 | filled_arrDoorTwo[i] = AlarmUtganger2 - filled_arrDoorTwo[i]; |
| andreped | 1:6917ec4f5e6d | 87 | } |
| andreped | 1:6917ec4f5e6d | 88 | if(i < 0 ) { |
| andreped | 8:bdb8bd12d4f4 | 89 | filled_arrDoorOne[i] = AlarmUtganger2 + filled_arrDoorTwo[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 | 8:bdb8bd12d4f4 | 99 | } |
| andreped | 8:bdb8bd12d4f4 | 100 | void fill_arrSone (float Sone1, float Sone2, float Sone3, float Sone4){ |
| andreped | 8:bdb8bd12d4f4 | 101 | filled_arrSone[4] = {Sone1, Sone2, Sone3, Sone4}; |
| andreped | 8:bdb8bd12d4f4 | 102 | |
| Banyrud | 7:25e0260ee887 | 103 | } |
| andreped | 8:bdb8bd12d4f4 | 104 | void fill_arrDoorOne(int Door1_1,int Door2_1,int Door3_1,int Door4_1) { |
| andreped | 8:bdb8bd12d4f4 | 105 | filled_arrDoorOne[0] = Door1_1; |
| andreped | 8:bdb8bd12d4f4 | 106 | filled_arrDoorOne[1] = Door2_1; |
| andreped | 8:bdb8bd12d4f4 | 107 | filled_arrDoorOne[2] = Door3_1; |
| andreped | 8:bdb8bd12d4f4 | 108 | filled_arrDoorOne[3] = Door4_1; |
| andreped | 8:bdb8bd12d4f4 | 109 | } |
| andreped | 8:bdb8bd12d4f4 | 110 | void fill_arrDoorTwo(int Door1_2,int Door2_2,int Door3_2,int Door4_2) { |
| andreped | 8:bdb8bd12d4f4 | 111 | filled_arrDoorOne[0] = Door1_2; |
| andreped | 8:bdb8bd12d4f4 | 112 | filled_arrDoorOne[1] = Door2_2; |
| andreped | 8:bdb8bd12d4f4 | 113 | filled_arrDoorOne[2] = Door3_2; |
| andreped | 8:bdb8bd12d4f4 | 114 | filled_arrDoorOne[3] = Door4_2; |
| andreped | 1:6917ec4f5e6d | 115 | } |
