GADGET RECIPE

Gadget Recipe

ブザーでメロディを鳴らす

コード

				
					<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>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()</code></pre>
</div>
				
			

カテゴリ

タグ

参考図

fig-002