from machine import Pin, PWM
import time
buzzer = Pin(15, Pin.OUT)
# Define notes (frequencies in Hz)
notes = {
'sa': 262,
're': 294,
'ga': 330,
'ma': 349,
'pa': 392,
'dha': 440,
'ni': 494,
'sa_high': 523
}
# Simple Saregama tune (note, duration in ms)
tune = [
('sa', 300), ('re', 300), ('ga', 300), ('sa', 300),
('ga', 300), ('ma', 300), ('pa', 300), ('pa', 600)
]
def play_tone(freq, duration):
pwm = PWM(buzzer)
pwm.freq(freq)
pwm.duty(512) # 50% duty cycle
time.sleep_ms(duration)
pwm.deinit()
time.sleep_ms(50)
for note, duration in tune:
play_tone(notes[note], duration)