hub.button – Button

The button module provides access to all buttons on the hub.

Attributes

hub.button.left

The left button.

hub.button.right

The right button.

hub.button.center

The center button.

hub.button.connect

The button with the Bluetooth symbol.

The Button class

class hub.button.Button

Provides access to button state and callback.

Each of the buttons listed above are instances of this class. You cannot instantiate additional button objects.

is_pressed()bool

Gets the state of the button.

Returns

True if it is pressed, False otherwise.

was_pressed()bool

Checks if this button was pressed since this method was last called.

Returns

True if it was pressed at least once since the previous call, False otherwise.

presses()int

Gets the number of times this button was pressed since this method was last called.

Returns

The number of presses since the last call.

callback(function: Callable[[int], None])None

Sets the callback function that is called when the button is pressed and when it is released.

The function must accept one argument, whose value indicates why the callback was called:

  • If the value is 0, the button is now pressed.

  • Otherwise, the button is now released. The value represents how many milliseconds it was pressed before it was released.

Parameters

function – Callable function that takes one argument. Choose None to disable the callback.