I am trying to follow this example. Everything works fine as expected with the following two lines
pir.when_motion = led.on
pir.when_no_motion = led.off
but things stop working when I assign an event handler to pir.when_motion
I can see function, turnOnLed
, and turnOffLed
getting invoked but can't see LED turning on and off.
Below is my code. Am I missing anything?
from gpiozero import MotionSensor , LED
from signal import pause
import time
pir = MotionSensor(4)
led = LED(16)
def logMessage(msg):
print(msg)
def turnOnLed():
logMessage('About to turn on LED...')
led.on
logMessage('LED turned on...')
def turnOffLed():
logMessage('About to turn off LED...')
led.off
logMessage('LED turned off...')
def myfun():
logMessage('Motion detected...')
pir.when_motion = led.on #If I replace led.on with event handler trunOnLed, I cant see LED switching on.
pir.when_no_motion = led.off
logMessage('Before pause')
pause()
Also, I have noticed that pir.when_no_motion
event is getting triggered immediately after about 4 seconds of pir.when_motion
even, if there is a continuous motion. Any pointers on what could be wrong?