from machine import Pin, I2C, PWM
import ssd1306
import time
# OLED setup
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
# Buzzer setup
buzzer = PWM(Pin(25))
buzzer.duty(0)
# Notes (frequencies)
notes = {
"C": 261, "D": 294, "E": 329,
"F": 349, "G": 392, "A": 440, "B": 493
}
# Lyrics + notes
song = [
("Now Playing", "C"),
("Bairan...", "E"),
("Mann mora...", "G"),
("Dil ye bole...", "A"),
("Aa re...", "C")
]
def play_note(note, duration):
buzzer.freq(notes[note])
buzzer.duty(512)
time.sleep(duration)
buzzer.duty(0)
# Scrolling function
def scroll_text(text, y, note):
for x in range(128, -len(text)*8, -2): # move left
oled.fill(0)
oled.text(text, x, y)
oled.show()
buzzer.freq(notes[note])
buzzer.duty(200) # soft continuous tone
time.sleep(0.03)
buzzer.duty(0)
while True:
for line, note in song:
scroll_text(line, 25, note)
time.sleep(0.3)