import machine
import time
buzzer_pin = machine.Pin(15, machine.Pin.OUT)  
buzzer_pwm = machine.PWM(buzzer_pin)
def play_note(frequency, duration):
    buzzer_pwm.freq(frequency)
    buzzer_pwm.duty_u16(32768) 
    time.sleep_ms(duration)
    buzzer_pwm.duty_u16(0)  
notes = {
    'C': 262, 'D': 294, 'E': 330, 'F': 349, 'G': 392, 'A': 440, 'B': 494, 'C+': 523
}
happy_birthday = ['G', 'G', 'A', 'G', 'C+', 'B', 'G', 'G', 'A', 'G', 'D', 'C+',
                  'G', 'G', 'G+', 'E', 'C+', 'B', 'A', 'F', 'F', 'E', 'C+', 'D', 'C+']
note_duration = 500  
for note in happy_birthday:
    if note in notes:
        play_note(notes[note], note_duration)
    else:
        time.sleep_ms(note_duration)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT