4.3. button Module

4.3.1. Button class

class button.Button(pin, debounce=50, long=600, active_low=False)

Button debounce class, handles button release and long presses.

Parameters
  • pin (int) – the pin number the button is connected to.

  • debounce (int optional) – the debounce time in ms, defaults to 50ms

  • long – (int optional): the long press interval, defaults to 600ms, a

  • of 0 will disable reporting of long presses. (value) –

  • active_high (bool optional) – if True pin reads 1 when pressed. If False

  • reads 0 when pressed. Defaults the True. (pin) –

modify(debounce=None, long=None)

Modify button debounce or long press timing

Parameters
  • debounce (int) – debounce time in ms

  • long (int) – long press time in ms

read()

Read button with debounce and long press detection

Returns

0 if not pressed. 1 if pressed, -1 if long pressed

Return type

int

4.3.2. JoyStick class

class button.JoyStick(buttons=None)

JoyStick class, handles reading a five way switch style joystick. Uses the Button class and supports long press notification.

read(max_wait=0)

Read JoyStick

Args: max_wait (optional int): maximum time to wait for button press

in ms.

Returns: int: the value of the button that was pressed and released.

if the button definition did not set the parameter long to 0, and the button was pressed and held longer then the parameter long in ms the value returned will be negative. If max_wait was specified and max_wait ms pass without a button being pressed amd release a 0 will be returned.