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 Alarmsystem_log_funksjon_funker_ikke by
Diff: main.cpp
- Revision:
- 1:6917ec4f5e6d
- Parent:
- 0:33bf28fd1ac6
- Child:
- 2:cef96d07d3cd
--- a/main.cpp Thu Jan 25 08:59:55 2018 +0000
+++ b/main.cpp Thu Jan 25 19:32:00 2018 +0000
@@ -1,29 +1,113 @@
#include "mbed.h"
-#define ON 1
-#define OFF 0
-#define AlarmSone1 1
-#define AlarmSone2 2
-#define AlarmSone3 4
-#define AlarmSone4 8
+#define Feil 0
+#define Tilstand1 (0.9<1.5)
+#define Tilstand2 (2.2<2.8)
+#define Tilstand3 (3<3.3)
+#define Normaldrift (0.01<0.2)
+
+#define _1MIN 600
DigitalOut Driftslys(LED1);
-BusOut Alarm(p21, p22, p23, p24);
+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);
+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;
-Ticker AlarmBlink;
+volatile int Utganger1 = AlarmUtganger1;
+volatile int Utganger2 = AlarmUtganger2;
+volatile int Bryter = Servicebryter;
+void Alarmf(void); //Funksjon for og pluss sammen bussen til alarmene
+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 main() {
- while(1) {
- Driftslys = 1;
-
- wait(0.2);
- myled = 0;
- wait(0.2);
}
}
+
+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] = Utganger1;
+ }
+ if(Tilstand2 == ArrSone[i]) {
+ AlarmBlink_Start();
+ DoorTwo[i] = Utganger2;
+ }
+ if(Tilstand3 == ArrSone[i]) {
+ AlarmBlink_Start();
+ DoorOne[i] = Utganger1;
+ DoorTwo[i] = Utganger2;
+ }
+ if(Feil == ArrSone[i]) {
+ AlarmBlink_Start();
+ }
+ if(Normaldrift == ArrSone[i]) {
+ Driftslys = 1;
+ DoorOne[i] = Utganger1 - DoorOne[i];
+ }
+ if(i < 0 ) {
+ DoorOne[i] = Utganger1 + DoorOne[i];
+ DoorTwo[i] = Utganger2 - DoorTwo[i];
+ }
+ if(i < 0 ) {
+ DoorOne[i] = Utganger2 + DoorTwo[i];
+ }
+ }
+ return ArrSone[i], DoorOne[i], DoorTwo[i];
+}
+
+void AlarmBlink_Start(void)
+{
+ sysclock = !sysclock;
+ Driftslys = 1;
+ if(Normaldrift == 1) {
+ sysclock = 1;
+ }
+}
\ No newline at end of file
