knut kristensen / Mbed 2 deprecated prosjektoppgave_alarm

Dependencies:   mbed

Fork of prosjektoppgave_alarm by PnM_spring17

Committer:
mathimat
Date:
Wed Jan 25 10:03:32 2017 +0000
Revision:
4:3dfc937f6516
Parent:
3:d3f95e1e06cf
Child:
5:b4e1656b6627
main;

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 1:fbad5dc82abd 7
mathimat 4:3dfc937f6516 8 Ticker alarmsjekk;
mathimat 1:fbad5dc82abd 9
mathimat 1:fbad5dc82abd 10 int brytere[8]; //en for hver bryter, 1 = alarm
mathimat 1:fbad5dc82abd 11 int status = 0; //1 = alarm
mathimat 1:fbad5dc82abd 12
mathimat 4:3dfc937f6516 13
mathimat 4:3dfc937f6516 14 //todo: få dette i en konfigurasjons tekstfil
mathimat 1:fbad5dc82abd 15 #define passord "qwerty"
mathimat 1:fbad5dc82abd 16 #define bryterAfrom 0
mathimat 1:fbad5dc82abd 17 #define bryterAto 0
mathimat 1:fbad5dc82abd 18 #define bryterBfrom 0
mathimat 1:fbad5dc82abd 19 #define bryterBto 0
mathimat 1:fbad5dc82abd 20 #define bryterABfrom 0
mathimat 1:fbad5dc82abd 21 #define bryterABto 0
mathimat 1:fbad5dc82abd 22 #define bryter0 0
mathimat 1:fbad5dc82abd 23
mathimat 1:fbad5dc82abd 24
mathimat 1:fbad5dc82abd 25 int alarmSjekk(AnalogIn& krets, int kretsn){
mathimat 1:fbad5dc82abd 26 /* Sjekker kretsen etter spenningsendring og returnerer hvilke bryter som er åpen
mathimat 1:fbad5dc82abd 27 -1 error
mathimat 1:fbad5dc82abd 28 0 alle lukket
mathimat 1:fbad5dc82abd 29 1 bryter A
mathimat 1:fbad5dc82abd 30 2 bryter B
mathimat 1:fbad5dc82abd 31 3 bryter AB
mathimat 1:fbad5dc82abd 32 */
mathimat 1:fbad5dc82abd 33 int bryter = -1;
mathimat 1:fbad5dc82abd 34 float volt = krets.read();
mathimat 1:fbad5dc82abd 35 if(volt <=bryter0){
mathimat 1:fbad5dc82abd 36 status = 1;
mathimat 1:fbad5dc82abd 37 if(bryterAfrom < volt < bryterAto){
mathimat 1:fbad5dc82abd 38 bryter = 1;
mathimat 1:fbad5dc82abd 39 brytere[kretsn*2] = 1;
mathimat 1:fbad5dc82abd 40 } else if(bryterBfrom < volt < bryterBto){
mathimat 1:fbad5dc82abd 41 bryter = 2;
mathimat 1:fbad5dc82abd 42 brytere[kretsn*2+1] = 1;
mathimat 1:fbad5dc82abd 43 } else if(bryterABfrom < volt){
mathimat 1:fbad5dc82abd 44 bryter = 3;
mathimat 1:fbad5dc82abd 45 brytere[kretsn*2] = brytere[kretsn*2+1] = 1;
mathimat 1:fbad5dc82abd 46 }
mathimat 1:fbad5dc82abd 47 } else(bryter = 0);
mathimat 1:fbad5dc82abd 48
mathimat 1:fbad5dc82abd 49 return bryter;
mathimat 1:fbad5dc82abd 50 }
mathimat 1:fbad5dc82abd 51
mathimat 1:fbad5dc82abd 52 void sjekkAlleKretser(){
mathimat 1:fbad5dc82abd 53 //sjekker alle kretser skvensielt for aktivering
mathimat 1:fbad5dc82abd 54 alarmSjekk(ain1, 0);
mathimat 3:d3f95e1e06cf 55 //alarmSjekk(ain2, 1);
mathimat 3:d3f95e1e06cf 56 //alarmSjekk(ain3, 2);
mathimat 3:d3f95e1e06cf 57 //alarmSjekk(ain4, 3);
mathimat 1:fbad5dc82abd 58 }
mathimat 1:fbad5dc82abd 59
mathimat 1:fbad5dc82abd 60 void statusLED(){
mathimat 1:fbad5dc82abd 61 //oppdatere statusLED til aktiverte alarmer
mathimat 1:fbad5dc82abd 62 for(int i=0; brytere[i]!=NULL;i++){
mathimat 1:fbad5dc82abd 63 if(brytere[i] == 1){
mathimat 3:d3f95e1e06cf 64 ledStatus = ledStatus+i;
mathimat 1:fbad5dc82abd 65 }
mathimat 1:fbad5dc82abd 66 }
mathimat 1:fbad5dc82abd 67 }
mathimat 1:fbad5dc82abd 68
mathimat 3:d3f95e1e06cf 69
mathimat 3:d3f95e1e06cf 70
mathimat 1:fbad5dc82abd 71 void resetSystem(){
mathimat 1:fbad5dc82abd 72 //reseter alarmsystemet
mathimat 1:fbad5dc82abd 73 for(int i=0; brytere[i]!=NULL;i++){
mathimat 1:fbad5dc82abd 74 brytere[i] = 0;
mathimat 1:fbad5dc82abd 75 }
mathimat 1:fbad5dc82abd 76 status = 0;
mathimat 1:fbad5dc82abd 77
mathimat 1:fbad5dc82abd 78 }
mathimat 0:0aa2d9849f98 79
mathimat 3:d3f95e1e06cf 80 void log(int status) {
mathimat 3:d3f95e1e06cf 81 switch(status){
mathimat 2:2d97a168af1e 82 }
mathimat 2:2d97a168af1e 83 }
mathimat 2:2d97a168af1e 84
mathimat 0:0aa2d9849f98 85 int main() {
mathimat 3:d3f95e1e06cf 86 while(1){
mathimat 3:d3f95e1e06cf 87 sjekkAlleKretser();
mathimat 3:d3f95e1e06cf 88 statusLED();
mathimat 3:d3f95e1e06cf 89 }
mathimat 0:0aa2d9849f98 90 }