from machine import Pin, PWM
from time import sleep_ms, sleep

BUZZER_PIN = 5

buzzer = PWM(Pin(BUZZER_PIN, Pin.OUT))

btnON = Pin(14, Pin.IN, Pin.PULL_DOWN)
btnOFF = Pin(27, Pin.IN, Pin.PULL_UP)

playing=False

def switchON(bt1):
    global playing
    playing = True

def switchOFF(bt2):
    global playing
    playing = False 

btnON.irq(trigger=Pin.IRQ_RISING, handler=switchON)
btnOFF.irq(trigger=Pin.IRQ_FALLING, handler=switchOFF)

note_frequencies = {
    "D": 294,
    "E": 330,
    "F": 350,
    "G": 392,
    "A": 440,
    "B": 494,
    "C": 528,
}

dutch_anthem_notes = [
    ("D", 0.5),
    ("G", 0.5),
    ("G", 0.5),
    ("A", 0.25),
    ("B", 0.25),
    ("C", 0.25),
    ("A", 0.25),
    ("B", 0.5),
    ("A", 0.25),
    ("B", 0.25),
    ("C", 0.5),
    ("B", 0.5),
    ("A", 0.25),
    ("G", 0.25),
    ("A", 0.5),
    ("G", 1.5),
]

while True:
    if playing:
        for nota, durata in dutch_anthem_notes:
            frequency = note_frequencies[nota]
            buzzer.duty(50)
            buzzer.freq(frequency)
            print("playing: "+str(nota))
            sleep(durata)
            buzzer.duty(0)
            sleep_ms(60)

$abcdeabcde151015202530fghijfghij