import machine
import utime

# Initialize PIR sensors and output devices
pir1 = machine.Pin(7, machine.Pin.IN, machine.Pin.PULL_DOWN)  # Bedroom PIR sensor
pir2 = machine.Pin(22, machine.Pin.IN, machine.Pin.PULL_DOWN)  # Living room PIR sensor
led = machine.Pin(26, machine.Pin.OUT)  # LED output
buzzer = machine.Pin(17, machine.Pin.OUT)  # Buzzer output

# Handle motion detection
def pir_handler(pin):
    utime.sleep_ms(100)  # Debounce
    if pin.value():
        if pin is pir1:
            print("Motion in bedroom!")
        elif pin is pir2:
            print("Motion in living room!")
        for i in range(50):  # Flash LED and buzzer
            led.toggle()
            buzzer.toggle()
            utime.sleep_ms(100)

# Set interrupts for PIR sensors
pir1.irq(trigger=machine.Pin.IRQ_RISING, handler=pir_handler)
pir2.irq(trigger=machine.Pin.IRQ_RISING, handler=pir_handler)

# Main loop: blink LED every second
while True:
    led.toggle()
    utime.sleep(1)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT