This example shows how to use the .value
attribute. Note that it is not a function and so does not use paranethseses. Here pir.value
is treated in the same way as you would a variable.
from gpiozero import MotionSensor
from time import sleep
pir = MotionSensor(12)
while True:
sleep(0.2)
if pir.value == 1:
print('motion detected')
This is functionally the same as:
from gpiozero import MotionSensor
from time import sleep
pir = MotionSensor(12)
while True:
sleep(0.2)
if pir.motion_detected:
print('motion detected')