from machine import Pin, PWM
from time import sleep
Sensor= Pin(2, Pin.IN)
Buzzer= PWM(Pin(3, Pin.OUT))
while True:
    if Sensor.value() == 1:
        Buzzer.freq(261)
        Buzzer.duty_u16(32768)
        sleep(1)
        Buzzer.duty_u16(0)
    else:
        sleep(0.1)
        Buzzer.duty_u16(0)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT