![](https://gadget-recipe.com/wp-content/uploads/2024/06/snippet-icon-300x225.png)
ブザーでメロディを鳴らす
コード
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()
カテゴリ
タグ
参考図
![fig-002 fig-002](https://gadget-recipe.com/wp-content/uploads/elementor/thumbs/fig-002-qpe97x3n96mf6in33qkedk4eo9w4zdzj3dzbz4fpji.png)