ブザーでメロディを鳴らす
コード
from machine import Pin
import time
C3 = 131
melodies = [C3, 0, C3, 0, C3]
duty = 50
delay = 0.375
p23 = Pin(23, Pin.OUT)
pwm = PWM(p23)
for note in melodies:
if note != 0:
pwm.freq(note)
pwm.duty(duty)
else:
pwm.duty(0)
time.sleep(delay)
pwm.duty(0)
pwm.deinit()
カテゴリ
タグ
参考図