knut kristensen / Mbed 2 deprecated prosjektoppgave_alarm

Dependencies:   mbed

Fork of prosjektoppgave_alarm by PnM_spring17

Committer:
mathimat
Date:
Wed Jan 18 10:26:14 2017 +0000
Revision:
1:fbad5dc82abd
Parent:
0:0aa2d9849f98
Child:
2:2d97a168af1e
en start;

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