Skip to content
Snippets Groups Projects
Commit 711ef7eb authored by Evan Jones's avatar Evan Jones
Browse files

Replace main.py

parent 37071e85
Branches
No related tags found
No related merge requests found
...@@ -5,11 +5,12 @@ import datetime ...@@ -5,11 +5,12 @@ import datetime
# Variables # Variables
light_port = 1 # A0 light_port = 1 # A0
pir_port = 2 # D2 pir_port = 4 # D4
button_port = 3 # D3 button_port = 3 # D2
#FOR SOME REASON THIS BOARD THINKS 3 IS D2
buzzer_port = 7 # D7 buzzer_port = 7 # D7
preferences {"Thingsboard": True, preferences = {"Thingsboard": True,
"Visual": True, "Visual": True,
"Audio": True} "Audio": True}
...@@ -30,19 +31,19 @@ def notify_thingsboard(message): ...@@ -30,19 +31,19 @@ def notify_thingsboard(message):
print("message") print("message")
return return
def notify_audio(duration=0.5): def notify_audio(duration):
digitalWrite(buzzer_port, 1) digitalWrite(buzzer_port, 1)
time.sleep(duration) time.sleep(duration)
digitalWrite(buzzer_port, 0) digitalWrite(buzzer_port, 0)
return return
def notify(preferences, message = "visitor"): def notify(preferences, message = "visitor", duration = 0.2):
if preferences.get("Thingsboard"): if preferences.get("Thingsboard"):
notify_thingsboard(message) notify_thingsboard(message)
elif preferences.get("Visual"): if preferences.get("Visual"):
notify_visual() notify_visual()
elif preferences.get("Audio"): if preferences.get("Audio"):
notify_audio() notify_audio(duration)
# === Main Reaction Loop === # === Main Reaction Loop ===
...@@ -53,39 +54,37 @@ def main_loop(): ...@@ -53,39 +54,37 @@ def main_loop():
try: try:
while True: while True:
# Check Button Press # Check Button Press
button = grovepi.digitalRead(button_port) button = digitalRead(button_port)
if button == 0: if button == 0:
print("[EVENT] Button Pressed") print("[EVENT] Button Pressed")
setText("RINGING") setText("RINGING")
notify_visual() notify(preferences)
time.sleep(2) time.sleep(2)
setText("Smart Doorbell\nReady") setText("Smart Doorbell\nReady")
# Check PIR # Check PIR
motion = grovepi.digitalRead(pir_port) motion = digitalRead(pir_port)
if motion: if motion:
print("[EVENT] Motion Detected") print("[EVENT] Motion Detected")
notify_thingsboard(f"[EVENT]({now}): Movement Detected") notify_thingsboard(f"[EVENT]({now}): Movement Detected")
time.sleep(1) #time.sleep(1)
# Check Light Level # Check Light Level
light = analogRead(light_port) light = analogRead(light_port)
if light < light_dark_threshold: if light < light_dark_threshold:
print("[INFO] Night Mode Active") #print("[INFO] Night Mode Active")
# You can dim screen, enable night light, etc. #Activate lights
# Or change color subtly to indicate night mode print()
else: else:
# Daytime color #print("daytime")
print()
time.sleep(0.2) time.sleep(0.2)
except KeyboardInterrupt: except KeyboardInterrupt:
print("Smart doorbell shutdown.") print("Smart doorbell shutdown.")
setText("System halted") setText("System halted")
setRGB(0, 0, 0)
# Run # Run
if __name__ == "__main__": if __name__ == "__main__":
Initialise_Sensors() initialise_sensors()
main_loop() main_loop()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment