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.
Dependencies: mbed
main.cpp
- Committer:
- andreped
- Date:
- 2018-01-30
- Revision:
- 3:26a7b2c4bed1
- Parent:
- 2:cef96d07d3cd
- Child:
- 4:aa2cff91ff4f
File content as of revision 3:26a7b2c4bed1:
#include "mbed.h"
#define Feil 0<1
#define Tilstand1 2.5<2.7
#define Tilstand2 2.1<2.3
#define Tilstand3 3.3
#define Normaldrift 1.8<2.0
DigitalOut Driftslys(LED1);
BusOut AlarmUtganger1(p21, p22, p23, p24);
BusOut AlarmUtganger2(p25, p26, p27, p28);
DigitalIn Servicebryter(p20);
DigitalIn _Sone1(p15);
DigitalIn _Sone2(p16);
DigitalIn _Sone3(p17);
DigitalIn _Sone4(p19);
Ticker AlarmBlink; //10Hz blinking for alarmfunksjon på lys og telling
int Tid = 0;
volatile int sysclock = 0;
volatile int Utganger1 = AlarmUtganger1;
volatile int Utganger2 = AlarmUtganger2;
volatile int Bryter = Servicebryter;
volatile int Door1_1 = 0, Door1_2 = 0, Door2_1 = 0, Door2_2 = 0, Door3_1 = 0, Door3_2 = 0, Door4_1 = 0, Door4_2 = 0;
volatile float Sone1 = _Sone1 * 3.3;
volatile float Sone2 = _Sone2 * 3.3;
volatile float Sone3 = _Sone3 * 3.3;
volatile float Sone4 = _Sone4 * 3.3;
volatile int ArrSone[4] = {Sone1, Sone2, Sone3, Sone4};
volatile int DoorOne[4] = { Door1_1, Door2_1, Door3_1, Door4_1 };
volatile int DoorTwo[4] = { Door1_2, Door2_2, Door3_2, Door4_2 };
enum {_Feil, _Tilstand1, _Tilstand2, _Tilstand3, _NormalDrift} Tilstand; // Tilstand1 = Bryter1 i Sonen valgt, Tilstand2 = Bryter2 i sonen valgt, Tilstand3 = bryter 1 og 2 i sonen valgt, Normaldrift = alt er optimalt.
int Tilstandssjekk();
void AlarmBlink_Start(void);
volatile int Klokke = 0;
int main()
{
AlarmBlink.attach(&AlarmBlink_Start, 0.05);
while(1) {
if(Servicebryter == 1) {
Utganger1 = 0;
Utganger2 = 0;
}
Tilstandssjekk();
while(sysclock == 1);
while(sysclock == 0);
Tid++;
}
}
int Tilstandssjekk()
{
static float Sone1 = Sone1 * 3.3;
static float Sone2 = Sone2 * 3.3;
static float Sone3 = Sone3 * 3.3;
static float Sone4 = Sone4 * 3.3;
int i = 0;
ArrSone[i];
DoorOne[i];
DoorTwo[i];
static int Utganger1;
static int Utganger2;
for(i = 0; i < 3; i++) {
if(ArrSone[i] == Tilstand1) {
AlarmBlink_Start();
DoorOne[i] = AlarmUtganger1;
}
if(Tilstand2 == ArrSone[i]) {
AlarmBlink_Start();
DoorTwo[i] = AlarmUtganger2;
}
if(Tilstand3 == ArrSone[i]) {
AlarmBlink_Start();
DoorOne[i] = AlarmUtganger1;
DoorTwo[i] = AlarmUtganger2;
}
if(Feil == ArrSone[i]) {
AlarmBlink_Start();
}
if(Normaldrift == ArrSone[i]) {
Driftslys = 1;
DoorOne[i] = AlarmUtganger1 - DoorOne[i];
}
if(i < 0 ) {
DoorOne[i] = AlarmUtganger1 + DoorOne[i];
DoorTwo[i] = AlarmUtganger2 - DoorTwo[i];
}
if(i < 0 ) {
DoorOne[i] = AlarmUtganger2 + DoorTwo[i];
}
}
return ArrSone[i], DoorOne[i], DoorTwo[i];
}
void AlarmBlink_Start(void)
{
sysclock = !sysclock;
Driftslys = 1;
if(Normaldrift == 1) {
sysclock = 1;
}
}