tinance2-doorbot/src/hardware.cpp

51 lines
976 B
C++
Raw Normal View History

2023-06-12 17:17:28 +00:00
#include "hardware.h"
#include "buzzer_ctl.h"
void controlRelay(int relayPin, bool on) {
digitalWrite(relayPin, on ? HIGH : LOW); // Turn the relay on or off
}
void unlockDoor(bool silent) {
#ifdef BUZZER
if (!silent) {
granted_beep();
}
#endif
#ifdef RELAY1
controlRelay(RELAY1_PIN,false);
#endif
#ifdef SERIAL_DEBUG
Serial.println("door unlocked");
#endif
#ifdef WEB_SERIAL_DEBUG
WebSerial.println("door unlocked");
#endif
}
void lockDoor() {
#ifdef RELAY1
controlRelay(RELAY1_PIN,true);
#endif
#ifdef SERIAL_DEBUG
Serial.println("door locked");
#endif
#ifdef WEB_SERIAL_DEBUG
WebSerial.println("door locked");
#endif
}
void toggleDoor() {
#ifdef RELAY1
int relayState = digitalRead(RELAY1_PIN);
// Toggle the relay based on the current state
if (relayState == LOW) {
lockDoor();
} else {
unlockDoor(false);
}
#endif
}