When running the following simple code, I would expect the [while True] to return an endless stream of 1 and 0, relating to the pir motion sensor state. However, once triggered, I only get 1s, even once motion has ended. If I do the opposite (ie, put the loop into a when_no_motion), I get a string of 0s... It seems that the pir.value is not updating.
Any clues?
Thanks in advance!
from signal import pause
from gpiozero import MotionSensor
pir = MotionSensor(4, queue_len=1)
def do_motion_detected():
while True:
print(pir.value)
pir.when_motion = do_motion_detected
pause()
It might also be worth noting that, when I try this with GPIOZero Button instead of MotionSensor, it works fine, giving me a stream of 1s and 0s, correlating to the Button value...
from signal import pause
from gpiozero import Button
clicker = Button(4)
def do_press_detected():
while True:
print(clicker.value)
clicker.when_pressed = do_press_detected
pause()