from machine import Pin, PWM
import time
buzzer = PWM(Pin(15))
buzzer.duty_u16(32768)
tones = {
'C': 262,
'D': 294,
'E': 330,
'F': 349,
'G': 392,
'A': 440,
'B': 494,
'C5': 523
}
melody = ['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C5']
print("演奏開始")
for note in melody:
freq = tones[note]
print(f"Note: {note}, Freq: {freq}Hz")
buzzer.freq(freq)
time.sleep(0.5)
print("停止")
buzzer.duty_u16(0)