from machine import Pin, PWM
import time
buzzer = PWM(Pin(15))
buzzer.duty_u16(0)
button = Pin(16, Pin.IN) # 外部プルダウン構成
# Wokwi: Pin("LED") の代わりにオンボードLED(GP25)を使用
led = Pin(25, Pin.OUT)
print("呼び鈴システム待機中...")
try:
while True:
if button.value() == 1:
led.on()
buzzer.duty_u16(32768)
buzzer.freq(660); time.sleep(0.5) # 高い音
buzzer.freq(523); time.sleep(1.0) # 低い音
buzzer.duty_u16(0)
led.off()
time.sleep(0.2)
time.sleep(0.05)
except KeyboardInterrupt:
buzzer.duty_u16(0); buzzer.deinit(); led.off()
print("停止")