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

  • buttonEUp - The Upper E button.
  • buttonEDown - The Lower E button.
  • buttonFUp - The Upper F button.
  • buttonFDown -The Lower F button.
  • buttonLUp - The Upper L Button.
  • buttonLDown - The Lower L Button.
  • buttonL3 - The L3 Button using the Left Joystick.
  • buttonRUp - The Upper R Button.
  • buttonRDown - The Lower R Button.
  • buttonR3 - The R3 Button using the Right Joystick.

  • buttonEUp - The Upper E button.
  • buttonEDown - The Lower E button.
  • buttonFUp - The Upper F button.
  • buttonFDown -The Lower F button.
  • buttonLUp - The Upper L Button.
  • buttonLDown - The Lower L Button.
  • buttonRUp - The Upper R Button.
  • buttonRDown - The Lower R Button.

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.