Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4906

Beginners • Re: Multiple PIR Problem

$
0
0
not tested.

Code:

from gpiozero import LED, MotionSensorfrom signal import pausefrom time import sleepimport threadingpir1=MotionSensor(21)pir2=MotionSensor(20)leds = [LED(2),        LED(3),        LED(4),        LED(5),        LED(6),        LED(7),]t1=00.25 # lights on delayt2=0.5 # lights off delayt3=3 # travel delayt4=0.1 # sweep delaysynchronized = threading.Lock()running = Falsedef up():    global running    with synchronized:        if running: return        running = True    print('up')    for led in leds:        led.on()        sleep(t1)    sleep(t3)    for led in leds:        led.off()        sleep(t2)    with synchronized:        running = False    def down():    global running    with synchronized:        if running: return        running = True    print('down')    for led in reversed(leds):        led.on()        sleep(t1)    sleep(t3)    for led in reversed(leds):        led.off()        sleep(t1)    with synchronized:        running = False    def sweep():    L1.on()    sleep(t4)    L2.on()    sleep(t4)    L3.on()    sleep(t4)    L4.on()    sleep(t4)    L5.on()    sleep(t4)    L6.on()    sleep(t4)    L6.off()    sleep(t4)    L5.off()    sleep(t4)    L4.off()    sleep(t4)    L3.off()    sleep(t4)    L2.off()    sleep(t4)    L1.off()def no_motion_function():    print("Motion stopped")sweep()print('Ready')pir1.when_motion = downpir2.when_motion = uppir1.when_no_motion = no_motion_functionpir2.when_no_motion = no_motion_functionpause()

Statistics: Posted by ghp — Sun Jan 14, 2024 4:16 am



Viewing all articles
Browse latest Browse all 4906

Trending Articles