I have a program for detecting motion in raspberry zero but I need to also have the capability to react when a button is pressed. But I can't. Can someone give me lights what should I do? The thing is working like this at first the pir is detecting motion, then it stops until I press the button, then I press the button and pir start to work again and I'm stuck in that bucle. I need both pir and button 'listening' at the same time My code (simplified) is working like this:
from gpiozero import MotionSensor
from gpiozero import Button
pir = MotionSensor(4)
button = Button(2)
postOnDb():
print("Posted on db")
turnOff():
print("Turned off")
while True:
pir.wait_for_motion()
postOnDB() #Every time the sensor detect motion this method should be call
button.wait_for_press() #At Any time this button is press program should call this method
turnOff()