Additional explanations

The button A is used to start the sound while the button B is used to stop the sound.

sound = False
    if cp.button_a:
        sound = True
    elif cp.button_b:
        cp.stop_tone()
        cp.pixels.fill((0, 0, 0))
        sound = False
    
    if not sound:
        continue

The note frequencies in the code correspond to the Hot Cross Buns song and need to be adjusted for other songs.

# These are the frequencies of the three notes.
note1 = 261.63
note2 = 293.66
note3 = 329.63

By default, the tilt value to switch from one note to another is 7° and needs to be adjusted depending on the balance board.

# If the balance board tilts beyond "tilt" degrees, different notes will be played.
tilt = 7

By default, the time to keep the board roughly horizontal is 0.7s. This allows quick modification of the tilt position and playing note 1 followed by note 3 (or vice versa) without playing note 2.

# Time (in seconds) to keep a horizontal position before note2 is played.
# This allows to switch from note1 to note3 (or vice versa) without playing note2.
horizontal = 0.7