fixed arm/unarm process

master
lux 5 years ago
parent f0087a401f
commit 6b467ece6e

@ -21,6 +21,8 @@ const int warnIncrement = 7; // increment maxLevel by this number
// Program booleans // Program booleans
bool isArmed = 1; // armed status. set to initialize as armed or unarmed bool isArmed = 1; // armed status. set to initialize as armed or unarmed
bool soundAlarm = 0; // should the program sound the alarm? bool soundAlarm = 0; // should the program sound the alarm?
bool unarmButtonDown = 0; // boolean that prevents unarm right after rearm
// until unarm button is depressed
// Program variables // Program variables
int warnLevel = 0; int warnLevel = 0;
@ -120,7 +122,8 @@ void loop() {
// - Arm/Unarm - // - Arm/Unarm -
if (digitalRead(armUnarm) == LOW || waitingForPass == 1) { if ((digitalRead(armUnarm) == LOW || waitingForPass == 1) &&
unarmButtonDown == 0) {
if (isArmed == 1 || waitingForPass == 1) { if (isArmed == 1 || waitingForPass == 1) {
if (waitingForPass == 0) { if (waitingForPass == 0) {
waitingForPass = 1; waitingForPass = 1;
@ -130,10 +133,10 @@ void loop() {
if (Serial.available()) { if (Serial.available()) {
char c = Serial.read(); char c = Serial.read();
readString += c;
if (c == '\n') { if (c != '\n') {
readString += c;
} else {
Serial.println(readString); Serial.println(readString);
if (readString == pass) { if (readString == pass) {
@ -158,14 +161,20 @@ void loop() {
flipLed(unarmedLed, flipflopUnarmState); flipLed(unarmedLed, flipflopUnarmState);
} }
} else { } else {
isArmed = 1; isArmed = 1;
waitingForPass = 0; waitingForPass = 0;
unarmButtonDown = 1;
playMelody(2, armMelody, armDurations, noteDelay); playMelody(2, armMelody, armDurations, noteDelay);
Serial.println("Successfully ARMED."); Serial.println("Successfully ARMED.");
} }
} }
// - Button safety -
if (digitalRead(armUnarm) == HIGH && unarmButtonDown == 1) {
unarmButtonDown = 0;
}
// - Activate unarmed/armed LEDs - // - Activate unarmed/armed LEDs -
if (isArmed == 1 && waitingForPass == 0 && soundAlarm == 0) { if (isArmed == 1 && waitingForPass == 0 && soundAlarm == 0) {

Loading…
Cancel
Save