from machine import Pin, PWM
from time import sleep
buzzer = PWM(Pin(15))
def tone(freq, t):
buzzer.duty(512) # duty cycle = 50%
buzzer.freq(freq)
sleep(t)
def silent(t):
buzzer.duty(0)
sleep(t)
#notes = [262,294,330,349,392,440,494,524]
notes = [659, 587, 370, 415,554, 494, 294, 330,494, 440, 277, 330,440]
for n in notes :
tone(n, 0.25)
silent(0.1)
for i in range(len(notes)-1 , -1 , -1) :
tone(notes[i], 0.25)
silent(0.1)