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 prosjektoppgave_alarm by
main.cpp
- Committer:
- Rocker79
- Date:
- 2017-01-25
- Revision:
- 8:0e77808699d0
- Parent:
- 6:5607f07a3863
- Child:
- 12:3d384401500c
File content as of revision 8:0e77808699d0:
#include "mbed.h"
AnalogIn ain1(p17), ain2(p18), ain3(p19), ain4(p20);
DigitalIn nullut(p16);
BusOut ledStatus(p21,p22,p23,p24,p25,p26,p27,p28);
DigitalOut ledMaster(LED1);
Serial pc(USBTX, USBRX);
PwmOut led(LED1);
Ticker tick;
int brytere[8]; //en for hver bryter, 1 = alarm
int status = 0; //1 = alarm
void blink()
{
if (status==0) {
led.period(0.1f);
led.write(1.0f);
} else {
led.period(0.1f);
led.write(0.5f);
}
}
//todo: få dette i en konfigurasjons tekstfil
#define passord "qwerty"
#define bryterAhigh 0.285f
#define bryterAlow 0.200f
#define bryterBhigh 0.200f
#define bryterBlow 0.150f
#define bryterABhigh 0.150f
#define bryterABlow 0.050f
#define bryter0 0.97f
void getFromFile() {
}
int alarmSjekk(AnalogIn& krets, int kretsn) {
/* Sjekker kretsen etter spenningsendring og returnerer hvilke bryter som er åpen
-1 error
0 alle lukket
1 bryter A
2 bryter B
3 bryter AB
---
*/
int bryter = -1;
float volt = krets.read();
pc.printf("volt %f", volt);
if(volt <= bryter0) {
status = 1;
if(volt < bryterAhigh) {
if(volt < bryterBhigh) {
if(volt < bryterABhigh) {
bryter = 3;
} else {
bryter = 2;
}
} else {
bryter = 1;
}
} else {
bryter = -2;
}
} else(bryter = 0);
return bryter;
}
void sjekkAlleKretser() {
//sjekker alle kretser skvensielt for aktivering
alarmSjekk(ain1, 0);
//alarmSjekk(ain2, 1);
//alarmSjekk(ain3, 2);
//alarmSjekk(ain4, 3);
}
void statusLED() {
//oppdatere statusLED til aktiverte alarmer
for(int i=0; brytere[i]!=NULL; i++) {
if(brytere[i] == 1) {
ledStatus = ledStatus+i;
}
}
}
void resetSystem() {
//reseter alarmsystemet
for(int i=0; brytere[i]!=NULL; i++) {
brytere[i] = 0;
}
status = 0;
}
void log(int status) {
switch(status) {
}
}
void chron() {
sjekkAlleKretser();
statusLED();
}
int main() {
while(1) {
int al = alarmSjekk(ain4, 4);
pc.printf(" Alarm Status: %d, Alarm %d gatt \r\n",status, al);
}
}
