from machine import Pin, PWM
from utime import sleep
from tones import melody, notes

buzzer = PWM(Pin(18))
buzzer.freq(2000)

buzzer.duty_u16(12000) # volume between 10 to 12000
sleep(0.5)
buzzer.duty_u16(0)
sleep(0.5)

# play the melody
for x in melody:
    noteName = x[0] # extract the note name
    duration = x[1] # extract the duration
    print("noteName = "noteName)
    buzzer.freq(notes[noteName])
   # if noteName is not "rest":
    buzzer.duty_u16(12000) # volume between 10 to 12000
    sleep.ms(duration)
    buzzer.duty_u16(0)

BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT