Welcome

This documentation will guide you through the methods available in the Button SHIM python library.

Button SHIM is a tiny Raspberry Pi add-on with 5 tactile buttons and one teeny RGB LED.

At A Glance

buttonshim.BUTTON_A = 0

Button A

buttonshim.BUTTON_B = 1

Button B

buttonshim.BUTTON_C = 2

Button C

buttonshim.BUTTON_D = 3

Button D

buttonshim.BUTTON_E = 4

Button E

buttonshim.NAMES = ['A', 'B', 'C', 'D', 'E']

Sometimes you want to print the plain text name of the button that’s triggered.

You can use:

buttonshim.NAMES[button_index]

To accomplish this.

buttonshim.on_hold(buttons, handler=None, hold_time=2)[source]
buttonshim.on_press(buttons, handler=None, repeat=False, repeat_time=0.5)[source]
buttonshim.on_release(buttons=None, handler=None)[source]
buttonshim.set_pixel(r, g, b)[source]

Set The Pixel

buttonshim.set_pixel(r, g, b)[source]

Set the Button SHIM RGB pixel

Display an RGB colour on the Button SHIM pixel.

Parameters:
  • r – Amount of red, from 0 to 255
  • g – Amount of green, from 0 to 255
  • b – Amount of blue, from 0 to 255

You can use HTML colours directly with hexadecimal notation in Python. EG:

buttonshim.set_pixel(0xFF, 0x00, 0xFF)

Handle A Button Press

buttonshim.on_press(buttons, handler=None, repeat=False, repeat_time=0.5)[source]

Attach a press handler to one or more buttons.

This handler is fired when you press a button.

When fired it will be run in its own Thread.

It will be passed two arguments, the button index and a boolean indicating whether the button has been pressed/released:

@buttonshim.on_press(buttonshim.BUTTON_A)
def handler(button, pressed):
    # Your code here
Parameters:
  • buttons – A single button, or a list of buttons
  • handler – Optional: a function to bind as the handler
  • repeat – Optional: Repeat the handler if the button is held
  • repeat_time – Optional: Time, in seconds, after which to repeat

Handle A Button Release

buttonshim.on_release(buttons=None, handler=None)[source]

Attach a release handler to one or more buttons.

This handler is fired when you let go of a button.

When fired it will be run in its own Thread.

It will be passed two arguments, the button index and a boolean indicating whether the button has been pressed/released:

@buttonshim.on_release(buttonshim.BUTTON_A)
def handler(button, pressed):
    # Your code here
Parameters:
  • buttons – A single button, or a list of buttons
  • handler – Optional: a function to bind as the handler

Handle A Button Hold

buttonshim.on_hold(buttons, handler=None, hold_time=2)[source]

Attach a hold handler to one or more buttons.

This handler is fired when you hold a button for hold_time seconds.

When fired it will run in its own Thread.

It will be passed one argument, the button index:

@buttonshim.on_press(buttonshim.BUTTON_A)
def handler(button):
    # Your code here
Parameters:
  • buttons – A single button, or a list of buttons
  • handler – Optional: a function to bind as the handler
  • hold_time – Optional: the hold time in seconds (default 2)

Get The Name Of A Button

buttonshim.NAMES = ['A', 'B', 'C', 'D', 'E']

Sometimes you want to print the plain text name of the button that’s triggered.

You can use:

buttonshim.NAMES[button_index]

To accomplish this.