# Super Mario Brothers (take 2) # Play the opening notes for Super Mario Brothers from time import sleep_ms from machine import Pin, PWM Spkr = PWM(Pin(18)) def Init(): Spkr.freq(100) Spkr.duty_u16(0) def Play(Hz, Eighths): if(Hz > 0): Spkr.freq(int(Hz)) Spkr.duty_u16(32768) else: Spkr.duty_u16(0) sleep_ms(75 * Eights - 50) Spkr.duty_u16(0) sleep_ms(50) G3 = 195 A3 = 220 B3 = 233 C4 = 262 D4 = 277 E4 = 330 F4 = 349 G4 = 392 A4 = 440 B4 = 494 Notes = [E4, E4, E4, 0, C4, E4, G4, 0, G3, 0] Dur = [2, 2, 4, 2, 2, 4, 4, 4, 4, 4] def Play_Tune(): for i in range(0, len(Notes)): Play(Notes[i], Dur[i]) Init() while(1): Play_Tune() time.sleep(1)