Welcome

This documentation will guide you through the methods available in the Piano HAT python library.

Piano HAT is a musical Raspberry Pi add-on with 13 capacitive-touch piano keys plus octave and instrument select pads.

At A Glance

pianohat.auto_leds(enable=True)[source]
pianohat.get_state(index=-1)[source]
pianohat.on_instrument(handler)[source]
pianohat.on_note(handler)[source]
pianohat.on_octave_down(handler)[source]
pianohat.on_octave_up(handler)[source]
pianohat.set_led(index, state)[source]
pianohat.set_led_ramp_rate(rise, fall)[source]

Automatic LEDs

pianohat.auto_leds(enable=True)[source]

Enable or disable automatic LEDs

Parameters:enable – enable or disable: True/False

on automatic, the corresponding LED will light when a key is touched and turn off when it is released.

Get A Button State

pianohat.get_state(index=-1)[source]

Get the state of a single key

Parameters:index – index of key to return, from 0 to 15

Instrument Button

pianohat.on_instrument(handler)[source]

Register handler for press/release of instrument key

Parameters:handler – handler function to register

See on_note for details.

Note

pianohat.on_note(handler)[source]

Register handler for press/release of note key

Parameters:handler – handler function to register

The handler function should expect two arguments.

The first is the button index that got the event, and the second is True for pressed and False for released.

Octave Down

pianohat.on_octave_down(handler)[source]

Register handler for press/release of octave_down key

Parameters:handler – handler function to register

See on_note for details.

Octave Up

pianohat.on_octave_up(handler)[source]

Register handler for press/release of octave_up key

Parameters:handler – handler function to register

See on_note for details.

Turn LED On/Off

pianohat.set_led(index, state)[source]

Turn an LED on or off

Parameters:
  • index – index of the LED to toggle: from 0 to 15
  • state – state to set the LED: either False or True

Change LED Transition Speed

pianohat.set_led_ramp_rate(rise, fall)[source]

Set the time it takes an LED to turn on or off

Parameters:
  • rise – time it takes LED to light in milliseconds
  • fall – time it takes LED to turn off in milliseconds