brian.buttons
- UiEventsListenerAlreadyClosedError
- LedColor
- LedEffect
- Button
- Knob
- top_left
- top_right
- bottom_left
- bottom_right
- any_button
- any_button_incl_knob
- knob
- enable_knob_rotation_animation
- use_os_colors
- use_raw_colors
- get_num_of_leds
- set_raw_led_colors
UiEventsListenerAlreadyClosedError class objects
Thrown when trying to access closed UiEventsListener
LedColor class objects
Color of a button LED.
__init__
Holds color definition for button LEDs. Color values range from 0 to 255. When outside of this range, the values are clamped
red
Red component of the color, in range from 0 to 255. When set to a value outside of this range, the value is clamped
green
Green component of the color, in range from 0 to 255. When set to a value outside of this range, the value is clamped
blue
Blue component of the color, in range from 0 to 255. When set to a value outside of this range, the value is clamped
LedEffect class objects
Constants for selecting the effect of button LEDs. Only in use when LED effects are handled by Brian OS.
OFF
LED is fully off
LOW
LED is pulsing at low brightness level
MEDIUM
LED is pulsing at medium brightness level
HIGH
LED is pulsing at high brightness level
inherit
LED effect is not set at this level; Effect of a previous (system) level is used.
Button class objects
A physical button of the brick. Pre-existing instances are available as
brian.buttons.top_left, top_right, bottom_left, bottom_right,
any_button and any_button_incl_knob — the class is not instantiable.
is_pressed
wait_for_press
Waits for next button press event.
This function is blocking.
Arguments:
timeout_ms: Maximum number of milliseconds to wait.- If the timeout is not provided or is None, the function will wait indefinitely.
Returns:
success: - True: If the desired button event was caught.
- False: If the timeout ran out.
wait_for_release
Waits for next button release event.
This function is blocking.
Arguments:
timeout_ms: Maximum number of milliseconds to wait.- If the timeout is not provided or is None, the function will wait indefinitely.
Returns:
success: - True: If the desired button event was caught.
- False: If the timeout ran out.
wait_for_press_and_release
Waits for next button press and release event.
This function is blocking.
Arguments:
timeout_ms: Maximum number of milliseconds to wait.- If the timeout is not provided or is None, the function will wait indefinitely.
Returns:
success: - True: If the desired button event was caught.
- False: If the timeout ran out.
set_led
Sets desired effect and color for the LED of this button. These settings override the effect
requested by the OS, unless LedEffect.inherit is used. For buttons.any_button and
buttons.any_button_incl_knob all respective buttons change color/effect.
Arguments:
effect: Target LED effect.color: Target color. When unfilled default color from settings is used.
Knob class objects
The physical knob of the brick. The pre-existing instance is available as
brian.buttons.knob — the class is not instantiable.
turned_to
Returns:
Absolute turn indent count (offset-corrected). Can be reset via reset_absolute_rotation().
wait_for_directional_turn
Waits for next directional turn of the knob.
This function is blocking.
Arguments:
clockwise: Whether to wait for clockwise or counterclockwise turn.timeout_ms: Maximum number of milliseconds to wait.- If the timeout is not provided or is None, the function will wait indefinitely.
Returns:
success: - True: If the desired button event was caught.
- False: If the timeout ran out.
wait_for_any_turn
Waits for next any turn of the knob.
This function is blocking.
Arguments:
timeout_ms: Maximum number of milliseconds to wait.- If the timeout is not provided or is None, the function will wait indefinitely.
Returns:
success: - True: If the desired button event was caught.
- False: If the timeout ran out.
reset_absolute_rotation
Resets turned_to() back to zero (or the provided value).
Arguments:
new_turned_to: Value that turned_to() should return immediately after this call. Defaults to 0.
top_left
Top left physical button. Live hardware state — no listener needed.
top_right
Top right physical button. Live hardware state — no listener needed.
bottom_left
Bottom left physical button. Live hardware state — no listener needed.
bottom_right
Bottom right physical button. Live hardware state — no listener needed.
any_button
Virtual button that reacts to any of the four corner buttons (knob excluded).
any_button_incl_knob
Virtual button that reacts to any of the four corner buttons or the knob press.
knob
The physical knob (rotation and press). Live hardware state — no listener needed.
enable_knob_rotation_animation
If enabled, OS automatically animates the LEDs under the knob when it rotates. The user program starts in the enabled state.
Arguments:
enabled: Whether to animate knob rotation.
use_os_colors
Returns button LED control to Brian OS (default state). Counterpart of :func:use_raw_colors.
use_raw_colors
Takes over full control of the button LEDs. After this call the LEDs show exactly the colors
set by :func:set_raw_led_colors — no OS effects are applied.
get_num_of_leds
Returns:
number of individually controllable button LEDs.