#!/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)