button#

Depending on if it is an EXP Controller or a V5 Controller connected, the button attribute has access to different objects:

EXP Controller

V5 Controller

  • buttonA - The A button.
  • buttonB - The B button.
  • buttonDown - The Down button.
  • buttonUp - The Up button.
  • buttonL1 - The L1 button.
  • buttonL2 - The L2 button.
  • buttonL3 - The L3 button.
  • buttonR1 - The R1 button.
  • buttonR2 - The R2 button.
  • buttonR3 - The R3 button.

  • buttonA - The A button.
  • buttonB - The B button.
  • buttonX - The X button.
  • buttonY - The Y button.
  • buttonDown - The Down button.
  • buttonUp - The Up button.
  • buttonLeft - The Left button.
  • buttonRight - The Right button.
  • buttonL1 - The L1 button.
  • buttonL2 - The L2 button.
  • buttonR1 - The R1 button.
  • buttonR2 - The R2 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.