Third party cookies may be stored when visiting this site. Please see the cookie information.

JLL Piano - Raspberry Pi Music Clip player

This project is called the JLL piano. This is a school project that my daughter created for her music homework. She needed to create a project that related to Jerry Lee Lewis and she created a mini piano that plays a short clip for a different song depending upon the key that is pressed.

Raspberry Pi Piano Hat

It uses a Raspberry Pi with a Pimoroni Piano Hat.

You first need to setup the Piano Hat using the Pimoroni Piano Hat install instructions. Then create the following in a text editor.

The program will work in Python 2 or Python 3.

You can of course change the music clips to be any music you prefer.

import pianohat

import time

from pygame import mixer

# Change key numbering (black keys = -1)

keys = [0,-1,1,-1,2,3,-1,4,-1,5,-1,6,7]

sound_files = [










def inc_volume(ch,evt):

if evt:


def dec_volume(ch,evt):

if evt:


# Change volume by amount specified 0 to 10 (+1, -1 etc.)

def change_volume (change):

#print ("Change volume "+str(change))

if change == 0 : return

# volume is 0 to 1 so divide by 10

delta = change / 10

new_volume = sounds[0].get_volume() + delta

if new_volume > 1:

new_volume = 1

if new_volume < 0:

new_volume = 0

for this_sound in sounds:


def handle_note(channel, pressed):

if pressed:

channel = keys[channel]

if (channel < 0):




mixer.init(22050, -16, 2, 512)


sounds = [mixer.Sound(sound_file) for sound_file in sound_files]




while True:


» PenguinTutor Facebook page