I require help with my alarm system code that I am building with GPIOZero library (my boss really likes the library). The system is meant for a laptop cart so people do not forget to close the door as there is a buzzer that rings if people leave it open for too long. So what I want it to do is really simple but it always waits for the function to finish before going to the next:
If door opens: Log time, Time Delay ,Buzzer turns on
If door is closed/closes: Buzzer is off, Log Time
Is there a way to not wait for the function to finish in the GPIOZero library. Please let me know!
from gpiozero import Button
from signal import pause
from gpiozero import Buzzer
from gpiozero import LED
from time import sleep
##### VARIABLES DEF #######
button = Button(21, pull_up=True)
buzzer = Buzzer(4)
def door_opened():
f = open("log" + '.txt', 'a')
f.write("Opened " + time.strftime("%m-%d-%Y %X"))
f.close()
print("Door Open")
sleep(100)
print("door held, alarm on")
buzzer.on
def door_closed():
f = open("log" + '.txt', 'a')
f.write(" " + time.strftime("%X"))
f.write('\n')
f.close()
print("Door Closed")
buzzer.off()
print("Buzzer off")
button.when_pressed = door_closed
button.when_released = door_opened
pause()