button#
The EXP Brain has access to three objects for its three buttons:
buttonCheckbuttonLeftbuttonRight
pressed()#
The pressed(callback, arg) method registers a function to be called when a button is pressed.
Parameters |
Description |
|---|---|
|
A function that will be called when the button is pressed. |
|
Optional. A tuple that is used to pass arguments to the callback function. |
Returns: An instance of the Event class.
# Define a function button_pressed().
def button_pressed():
# The Brain will print that the button was pressed on
# the Brain's screen.
brain.screen.print("button pressed")
# Run button_pressed() when the left button is pressed.
brain.buttonLeft.pressed(button_pressed)
released()#
The released(callback, arg) method registers a function to be called when a button is released.
Parameters |
Description |
|---|---|
|
A function that will be called when the button is released. |
|
Optional. A tuple that is used to pass arguments to the callback function. |
Returns: An instance of the Event class.
# Define a function button_released().
def button_released():
# The Brain will print that the button was released on
# the Brain's screen.
brain.screen.print("button released")
# Run button_released() when the left button is released.
brain.buttonLeft.released(button_released)
pressing()#
The pressing() method returns whether a button is currently being pressed.
Returns: True if the button is being pressed. False if it is not.