from machine import Pin, PWM, Timer
from time import sleep
toque = {'nota':(294,392,523,494,392,329,440,587),
'duracao': (563,188,1125,375,281,281,281,1500)}
qteNotas = len (toque ['nota']) # Quantas notas no total
qual = 1 # Qual nota deverá ser tocada
buzzer = PWM(Pin(22))
tempo = Timer()
def execute(t):
global toque, qteNotas, qual, buzzer
if qual < qteNotas:
buzzer.freq(toque ['nota'] [qual])
tempo.init (mode=Timer.ONE_SHOT, period=toque ['duracao'] [qual],
callback=execute)
qual += 1