bathroom-timer/door.py
Vincent Batts b10dcbba57
*: initial toying with gpiozero python3
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2024-11-15 21:08:19 -05:00

39 lines
649 B
Python

#!/usr/bin/env python3
from gpiozero import Button, Buzzer
from time import sleep
from datetime import datetime
# https://docs.python.org/3/library/datetime.html#datetime.datetime.now
# the door sensor
door = Button(23)
btn = Button(19)
bz = Buzzer(26)
#bz.on()
#bz.off()
def alarm():
bz.beep(0.5,0.25,8)
def doorClosed():
t = datetime.now()
print(f"{t} - door closed. LED on")
def doorOpen():
t = datetime.now()
print(f"{t} - door open. LED off")
def whenPressed():
bz.toggle()
btn.when_pressed = whenPressed
door.when_pressed = doorClosed
door.when_released = doorOpen
print("ready")
while True:
sleep(0.2)