diff --git a/zuno/zuno.ino b/zuno/zuno.ino index a5374bb..1eeeb61 100644 --- a/zuno/zuno.ino +++ b/zuno/zuno.ino @@ -71,6 +71,7 @@ int btn_unlock_current_state = LOW; int btn_unlock_debounce = 0; int activity_flash = 0; +int buzzer_flash = 0; int servo_status = 0; int source_status = 0; @@ -79,6 +80,7 @@ unsigned long activity_timestamp = 0; unsigned long servo_timestamp = 0; unsigned long rfid_timeout_timestamp = 0; unsigned long alarm_timestamp = 0; +unsigned long buzzer_timestamp = 0; bool lock_disable = false; @@ -99,7 +101,7 @@ bool rfid_store_tag = false; #define ALARM_PRE_STAGE_WAITING 1 #define ALARM_PRE_STAGE_ENABLED 2 -int alarm_pre_activate = 0; +int alarm_pre_activate = ALARM_PRE_STAGE_DISABLED; bool alarm_activate = false; bool alarm_confirmed = false; bool alarm_waiting_for_confirmation = false; @@ -357,9 +359,17 @@ void setup() { set_servo(SERVO_CENTER, SOURCE_SYSTEM); pinMode(BUZZER_PIN, OUTPUT); // setup pin as output - digitalWrite(BUZZER_PIN, HIGH); - delay(200); digitalWrite(BUZZER_PIN, LOW); + + // Test (show) indicators and buzzer + digitalWrite(BUZZER_PIN, HIGH); + digitalWrite(LED_UNLOCK_PIN, HIGH); + digitalWrite(LED_LOCK_PIN, HIGH); + delay(500); + digitalWrite(BUZZER_PIN, LOW); + digitalWrite(LED_UNLOCK_PIN, LOW); + digitalWrite(LED_LOCK_PIN, LOW); + delay(1000); } @@ -452,6 +462,28 @@ void loop() { zunoSendReport(6); } } + + // Buzzer indication for ALARM status + if (alarm_waiting_for_confirmation == true){ + digitalWrite(BUZZER_PIN, HIGH); + } + else if (alarm_pre_activate == ALARM_PRE_STAGE_ENABLED){ + if (current_timestamp >= buzzer_timestamp) { + if (buzzer_flash == 0){ + digitalWrite(BUZZER_PIN, HIGH); + buzzer_flash = 1; + buzzer_timestamp = current_timestamp + 100; + } + else{ + digitalWrite(BUZZER_PIN, LOW); + buzzer_flash = 0; + buzzer_timestamp = current_timestamp + 1000; + } + } + } + else{ + digitalWrite(BUZZER_PIN, LOW); + } // Indicate that the door is being locked if (servo_status == SERVO_LOCK){ @@ -469,6 +501,7 @@ void loop() { activity_timestamp = current_timestamp + 50; } } + // Indicate that the door is being unlocked else if (servo_status == SERVO_UNLOCK){ if (current_timestamp >= activity_timestamp) { @@ -485,6 +518,7 @@ void loop() { activity_timestamp = current_timestamp + 50; } } + else if (servo_status == SERVO_DISABLE){ // Indicate RFID storing mode if (rfid_store_tag_nbr > 0){ @@ -492,19 +526,20 @@ void loop() { digitalWrite(LED_UNLOCK_PIN, HIGH); } // Indicate that pre Alarm activation has been enabled - else if (alarm_pre_activate == 2){ + else if (alarm_pre_activate == ALARM_PRE_STAGE_ENABLED){ if (current_timestamp >= activity_timestamp) { if (activity_flash == 0){ digitalWrite(LED_LOCK_PIN, HIGH); digitalWrite(LED_UNLOCK_PIN, HIGH); activity_flash = 1; + activity_timestamp = current_timestamp + 100; } else{ digitalWrite(LED_LOCK_PIN, LOW); digitalWrite(LED_UNLOCK_PIN, HIGH); activity_flash = 0; + activity_timestamp = current_timestamp + 1000; } - activity_timestamp = current_timestamp + 250; } } // Indicate that the lock/unlock is disabled