27.02.2018
Dependencies: Matrix
Fork of Alarmsystem_log_funksjon_funker_ikke by
main.cpp@10:f0a6d74095d4, 2018-02-09 (annotated)
- Committer:
- andreped
- Date:
- Fri Feb 09 07:51:55 2018 +0000
- Revision:
- 10:f0a6d74095d4
- Parent:
- 6:a3b97bf7902b
- Child:
- 11:dad1798ed88f
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andreped | 0:33bf28fd1ac6 | 1 | #include "mbed.h" |
andreped | 6:a3b97bf7902b | 2 | #include <vector> |
andreped | 0:33bf28fd1ac6 | 3 | |
andreped | 6:a3b97bf7902b | 4 | #define Inn 4 |
andreped | 6:a3b97bf7902b | 5 | //#define Feil 0<1 |
andreped | 10:f0a6d74095d4 | 6 | |
andreped | 6:a3b97bf7902b | 7 | |
andreped | 6:a3b97bf7902b | 8 | //DigitalOut myled2(LED2); |
andreped | 4:aa2cff91ff4f | 9 | Serial pc(USBTX, USBRX); |
andreped | 0:33bf28fd1ac6 | 10 | DigitalOut Driftslys(LED1); |
andreped | 10:f0a6d74095d4 | 11 | BusOut AlarmUtganger1(p21, p22, p23, p24); //1 - Dør 1 Sone 1, 2 - Dør 1 Sone 2, 4 - Dør 1 Sone 3, 8 - Dør 1 Sone 4 |
andreped | 10:f0a6d74095d4 | 12 | BusOut AlarmUtganger2(p25, p26, p27, p28); //1 - Dør 2 Sone 1, 2 - Dør 2 Sone 2, 4 - Dør 2 Sone 3, 8 - Dør 2 Sone 4 |
andreped | 0:33bf28fd1ac6 | 13 | DigitalIn Servicebryter(p20); |
andreped | 6:a3b97bf7902b | 14 | AnalogIn _Sone1(p15); AnalogIn _Sone2(p16); AnalogIn _Sone3(p17); AnalogIn _Sone4(p19); |
andreped | 6:a3b97bf7902b | 15 | float Soner[Inn]; |
andreped | 10:f0a6d74095d4 | 16 | int tilstand1(int i); |
andreped | 0:33bf28fd1ac6 | 17 | |
andreped | 10:f0a6d74095d4 | 18 | //Ticker AlarmBlink; // 10Hz blinking for alarmfunksjon på lys og telling |
andreped | 6:a3b97bf7902b | 19 | //nt Tid = 0; |
andreped | 6:a3b97bf7902b | 20 | //volatile int sysclock = 0; |
andreped | 1:6917ec4f5e6d | 21 | |
andreped | 1:6917ec4f5e6d | 22 | int Tilstandssjekk(); |
andreped | 6:a3b97bf7902b | 23 | //void AlarmBlink_Start(void); |
andreped | 6:a3b97bf7902b | 24 | //volatile int Klokke = 0; |
andreped | 1:6917ec4f5e6d | 25 | |
andreped | 1:6917ec4f5e6d | 26 | int main() |
andreped | 1:6917ec4f5e6d | 27 | { |
andreped | 6:a3b97bf7902b | 28 | //AlarmBlink.attach(&AlarmBlink_Start, 0.05); |
andreped | 1:6917ec4f5e6d | 29 | |
andreped | 1:6917ec4f5e6d | 30 | while(1) { |
andreped | 6:a3b97bf7902b | 31 | /*if(Servicebryter == 1) { |
andreped | 1:6917ec4f5e6d | 32 | Utganger1 = 0; |
andreped | 1:6917ec4f5e6d | 33 | Utganger2 = 0; |
andreped | 6:a3b97bf7902b | 34 | }*/ |
andreped | 6:a3b97bf7902b | 35 | Soner[0] = _Sone1; |
andreped | 6:a3b97bf7902b | 36 | //Soner[1] = _Sone2; |
andreped | 6:a3b97bf7902b | 37 | //Soner[2] = _Sone3; |
andreped | 6:a3b97bf7902b | 38 | //Soner[3] = _Sone4; |
andreped | 6:a3b97bf7902b | 39 | for(int i=0; i < Inn; i++) { |
andreped | 6:a3b97bf7902b | 40 | pc.printf("%f\n", Soner[i]); |
andreped | 6:a3b97bf7902b | 41 | if((Soner[i] > 0.75 )&&( Soner[i] < 0.83)) { //Tilstand1, Dør 1 åpen |
andreped | 6:a3b97bf7902b | 42 | pc.printf("Vi er i Tilstand1\n"); |
andreped | 10:f0a6d74095d4 | 43 | Tilstand1(i); |
andreped | 6:a3b97bf7902b | 44 | } |
andreped | 6:a3b97bf7902b | 45 | if((Soner[i] > 0.55 )&&( Soner[i] < 0.59)) { //Normaldrift |
andreped | 6:a3b97bf7902b | 46 | pc.printf("Vi er i Normaldrift\n"); |
andreped | 6:a3b97bf7902b | 47 | } |
andreped | 6:a3b97bf7902b | 48 | if((Soner[i] > 0.65 )&&( Soner[i] < 0.69)) { //Tilstand 2, Dør 2 åpen |
andreped | 6:a3b97bf7902b | 49 | pc.printf("Vi er i tilstand2\n"); |
andreped | 6:a3b97bf7902b | 50 | } |
andreped | 6:a3b97bf7902b | 51 | if(Soner[i] >= 1) { //Begge dører er åpne |
andreped | 6:a3b97bf7902b | 52 | pc.printf("Vi er i tilstand 3, begge doorer er aapne"); |
andreped | 6:a3b97bf7902b | 53 | } |
andreped | 6:a3b97bf7902b | 54 | wait(1.5); |
andreped | 1:6917ec4f5e6d | 55 | } |
andreped | 6:a3b97bf7902b | 56 | //pc.printf("%f\n", Sone1[]); |
andreped | 6:a3b97bf7902b | 57 | //Tilstandssjekk(Sone1[]); |
andreped | 6:a3b97bf7902b | 58 | //float volt = Sone1[]; |
andreped | 6:a3b97bf7902b | 59 | //pc.printf("%f\n", volt); |
Banyrud | 5:045ef3068f21 | 60 | //while(sysclock == 1); |
Banyrud | 5:045ef3068f21 | 61 | //while(sysclock == 0); |
andreped | 6:a3b97bf7902b | 62 | //Tid++; |
andreped | 0:33bf28fd1ac6 | 63 | } |
andreped | 0:33bf28fd1ac6 | 64 | } |
andreped | 1:6917ec4f5e6d | 65 | |
andreped | 10:f0a6d74095d4 | 66 | int Tilstand1(int a) { |
andreped | 10:f0a6d74095d4 | 67 | AlarmUtganger1 = pow(2, a); //Alarmutganger operer med binærtall så bytter ut |
andreped | 10:f0a6d74095d4 | 68 | } |
andreped | 1:6917ec4f5e6d | 69 | |
andreped | 6:a3b97bf7902b | 70 | /*void AlarmBlink_Start(void) |
andreped | 1:6917ec4f5e6d | 71 | { |
andreped | 1:6917ec4f5e6d | 72 | sysclock = !sysclock; |
andreped | 1:6917ec4f5e6d | 73 | Driftslys = 1; |
andreped | 1:6917ec4f5e6d | 74 | if(Normaldrift == 1) { |
andreped | 1:6917ec4f5e6d | 75 | sysclock = 1; |
andreped | 1:6917ec4f5e6d | 76 | } |
andreped | 6:a3b97bf7902b | 77 | }*/ |