knut kristensen / Mbed 2 deprecated prosjektoppgave_alarm

Dependencies:   mbed

Fork of prosjektoppgave_alarm by PnM_spring17

Committer:
mathimat
Date:
Wed Jan 25 11:52:38 2017 +0000
Revision:
12:3d384401500c
Parent:
8:0e77808699d0
Child:
13:892212c61603
Works for now

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mathimat 0:0aa2d9849f98 1 #include "mbed.h"
mathimat 0:0aa2d9849f98 2
mathimat 1:fbad5dc82abd 3 AnalogIn ain1(p17), ain2(p18), ain3(p19), ain4(p20);
mathimat 1:fbad5dc82abd 4 DigitalIn nullut(p16);
mathimat 1:fbad5dc82abd 5 BusOut ledStatus(p21,p22,p23,p24,p25,p26,p27,p28);
mathimat 1:fbad5dc82abd 6 DigitalOut ledMaster(LED1);
mathimat 6:5607f07a3863 7 Serial pc(USBTX, USBRX);
Rocker79 8:0e77808699d0 8 PwmOut led(LED1);
Rocker79 8:0e77808699d0 9
mathimat 1:fbad5dc82abd 10
mathimat 5:b4e1656b6627 11 Ticker tick;
mathimat 1:fbad5dc82abd 12
mathimat 1:fbad5dc82abd 13 int brytere[8]; //en for hver bryter, 1 = alarm
mathimat 1:fbad5dc82abd 14 int status = 0; //1 = alarm
mathimat 1:fbad5dc82abd 15
Rocker79 8:0e77808699d0 16
mathimat 4:3dfc937f6516 17
mathimat 4:3dfc937f6516 18 //todo: få dette i en konfigurasjons tekstfil
mathimat 1:fbad5dc82abd 19 #define passord "qwerty"
mathimat 6:5607f07a3863 20 #define bryterAhigh 0.285f
mathimat 6:5607f07a3863 21 #define bryterAlow 0.200f
mathimat 6:5607f07a3863 22 #define bryterBhigh 0.200f
mathimat 6:5607f07a3863 23 #define bryterBlow 0.150f
mathimat 6:5607f07a3863 24 #define bryterABhigh 0.150f
mathimat 6:5607f07a3863 25 #define bryterABlow 0.050f
mathimat 6:5607f07a3863 26 #define bryter0 0.97f
mathimat 1:fbad5dc82abd 27
mathimat 1:fbad5dc82abd 28
mathimat 12:3d384401500c 29 void getFromFile()
mathimat 12:3d384401500c 30 {
mathimat 12:3d384401500c 31
mathimat 12:3d384401500c 32 }
Rocker79 8:0e77808699d0 33
mathimat 12:3d384401500c 34 void blink()
mathimat 12:3d384401500c 35 {
mathimat 12:3d384401500c 36 if (status==0) {
mathimat 12:3d384401500c 37 led.period(0.1f);
mathimat 12:3d384401500c 38 led.write(1.0f);
mathimat 12:3d384401500c 39 } else {
mathimat 12:3d384401500c 40 led.period(0.1f);
mathimat 12:3d384401500c 41 led.write(0.5f);
Rocker79 8:0e77808699d0 42 }
mathimat 6:5607f07a3863 43
mathimat 12:3d384401500c 44 }
mathimat 12:3d384401500c 45
mathimat 12:3d384401500c 46 int alarmSjekk(AnalogIn& krets, int kretsn)
mathimat 12:3d384401500c 47 {
mathimat 12:3d384401500c 48 /* Sjekker kretsen etter spenningsendring og returnerer hvilke bryter som er åpen
mathimat 12:3d384401500c 49 -1 error
mathimat 12:3d384401500c 50 0 alle lukket
mathimat 12:3d384401500c 51 1 bryter A
mathimat 12:3d384401500c 52 2 bryter B
mathimat 12:3d384401500c 53 3 bryter AB
mathimat 12:3d384401500c 54 ---
mathimat 12:3d384401500c 55 */
mathimat 12:3d384401500c 56 int bryter = -1;
mathimat 12:3d384401500c 57 float volt = krets.read();
mathimat 12:3d384401500c 58 pc.printf("volt %f", volt);
mathimat 12:3d384401500c 59 if(volt <= bryter0) {
mathimat 12:3d384401500c 60 status = 1;
mathimat 12:3d384401500c 61 if(volt < bryterAhigh) {
mathimat 12:3d384401500c 62 if(volt < bryterBhigh) {
mathimat 12:3d384401500c 63 if(volt < bryterABhigh) {
mathimat 12:3d384401500c 64 bryter = 3;
mathimat 6:5607f07a3863 65 } else {
mathimat 12:3d384401500c 66 bryter = 2;
mathimat 6:5607f07a3863 67 }
mathimat 6:5607f07a3863 68 } else {
mathimat 12:3d384401500c 69 bryter = 1;
mathimat 6:5607f07a3863 70 }
mathimat 12:3d384401500c 71 } else {
mathimat 12:3d384401500c 72 bryter = -2;
mathimat 12:3d384401500c 73 }
mathimat 12:3d384401500c 74 } else(bryter = 0);
Rocker79 8:0e77808699d0 75
mathimat 12:3d384401500c 76 return bryter;
mathimat 12:3d384401500c 77 }
mathimat 1:fbad5dc82abd 78
mathimat 12:3d384401500c 79 void sjekkAlleKretser()
mathimat 12:3d384401500c 80 {
mathimat 12:3d384401500c 81 //sjekker alle kretser skvensielt for aktivering
mathimat 12:3d384401500c 82 alarmSjekk(ain1, 0);
mathimat 12:3d384401500c 83 //alarmSjekk(ain2, 1);
mathimat 12:3d384401500c 84 //alarmSjekk(ain3, 2);
mathimat 12:3d384401500c 85 //alarmSjekk(ain4, 3);
mathimat 12:3d384401500c 86 }
mathimat 1:fbad5dc82abd 87
mathimat 12:3d384401500c 88 void statusLED()
mathimat 12:3d384401500c 89 {
mathimat 12:3d384401500c 90 //oppdatere statusLED til aktiverte alarmer
mathimat 12:3d384401500c 91 for(int i=0; brytere[i]!=NULL; i++) {
mathimat 12:3d384401500c 92 if(brytere[i] == 1) {
mathimat 12:3d384401500c 93 ledStatus = ledStatus+i;
mathimat 1:fbad5dc82abd 94 }
mathimat 1:fbad5dc82abd 95 }
mathimat 12:3d384401500c 96 }
mathimat 1:fbad5dc82abd 97
mathimat 3:d3f95e1e06cf 98
mathimat 3:d3f95e1e06cf 99
mathimat 12:3d384401500c 100 void resetSystem()
mathimat 12:3d384401500c 101 {
mathimat 12:3d384401500c 102 //reseter alarmsystemet
mathimat 12:3d384401500c 103 for(int i=0; brytere[i]!=NULL; i++) {
mathimat 12:3d384401500c 104 brytere[i] = 0;
mathimat 12:3d384401500c 105 }
mathimat 12:3d384401500c 106 status = 0;
Rocker79 8:0e77808699d0 107
mathimat 12:3d384401500c 108 }
mathimat 0:0aa2d9849f98 109
mathimat 12:3d384401500c 110 void log(int status)
mathimat 12:3d384401500c 111 {
mathimat 12:3d384401500c 112 switch(status) {
mathimat 2:2d97a168af1e 113 }
mathimat 12:3d384401500c 114 }
mathimat 2:2d97a168af1e 115
mathimat 12:3d384401500c 116 void chron()
mathimat 12:3d384401500c 117 {
mathimat 12:3d384401500c 118 sjekkAlleKretser();
mathimat 12:3d384401500c 119 statusLED();
mathimat 12:3d384401500c 120 }
mathimat 5:b4e1656b6627 121
mathimat 5:b4e1656b6627 122
mathimat 12:3d384401500c 123 int main()
mathimat 12:3d384401500c 124 {
mathimat 12:3d384401500c 125 while(1) {
mathimat 12:3d384401500c 126 int al = alarmSjekk(ain4, 4);
mathimat 12:3d384401500c 127 pc.printf(" Alarm Status: %d, Alarm %d gatt \r\n",status, al);
mathimat 3:d3f95e1e06cf 128 }
mathimat 12:3d384401500c 129 }