button#
Depending on if it is an IQ (2nd gen) Controller of an IQ (1st gen) Controller, the button
attribute has access to different objects:
IQ (2nd gen) Controller |
IQ (1st gen) Controller |
---|---|
|
|
pressed()#
The pressed(callback, arg)
method registers a function to be called when a Controller’s button is pressed.
Parameter |
Description |
---|---|
callback |
A function that will be called when the button is pressed |
arg |
Optional. A tuple that is used to pass a parameter 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 L1 button is pressed.
controller.buttonL1.pressed(button_pressed)
released()#
The released(callback, arg)
method registers a function to be called when a Controller’s button is released.
Parameter |
Description |
---|---|
callback |
A function that will be called when the button is released |
arg |
Optional. A tuple that is used to pass a parameter 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 L1 button is released.
controller.buttonL1.released(button_released)
pressing()#
The pressing()
method returns whether a Controller’s button is currently being pressed.
Returns: True
if the button is currently being pressed. False
if it is not currently being pressed.