from machine import Pin, PWM
from time import sleep_ms, sleep
buzzer = PWM(Pin(0))
melodies = [
[(262, 100), (330, 100), (392, 100), (523, 400)],
[(523, 150), (440, 150), (349, 150), (262, 500)],
[(392, 400), (330, 400), (294, 200)],
[(262, 50), (392, 50), (523, 50), (392, 50), (262, 600)],
[(330, 200), (349, 200), (440, 200), (494, 200)],
[(494, 300), (392, 100), (294, 300), (523, 300)],
[(294, 200), (294, 200), (330, 400), (392, 200)],
[(523, 200), (349, 200), (440, 200), (262, 400)],
[(440, 100), (494, 100), (523, 500)],
[(262, 500), (392, 300), (494, 200)],
[(330, 200), (523, 200), (330, 200), (262, 400)],
[(392, 300), (349, 300), (330, 300)],
[(440, 100), (392, 100), (330, 400), (294, 400)],
[(294, 200), (494, 200), (349, 200), (523, 300)],
[(523, 200), (392, 100), (523, 200), (392, 100)],
[(262, 300), (330, 300), (392, 300), (262, 500)]
]
def play_melody(melody):
for freq, dur in melody:
buzzer.freq(freq)
buzzer.duty(400)
sleep_ms(dur)
buzzer.duty(0)
sleep(0.1)
while True:
for i, melody in enumerate(melodies):
print("Мелодія", i + 1)
play_melody(melody)
sleep(1)