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