#

介绍#

VEX IQ(第二代)大脑感应类别提供了与大脑按钮和连接电池交互的方法。

以下是所有方法的列表:

操作——与 VEX IQ(第二代)按钮交互。

  • pressed – Calls a function when the specified button is pressed.

  • released – Calls a function when the specified button is released.

Getters – 从按钮和电池返回数据。

  • pressing – Returns whether the specified button is being pressed.

  • capacity – Returns the remaining battery capacity as a percentage.

  • voltage – Returns the voltage of the battery.

  • current – Returns the current drawn by the battery.

构造函数——手动初始化大脑。

  • brain – Create a brain.

行动#

pressed#

pressed registers a function to be called when a specific button on the Brain is pressed. This method must be called on a specific button object, such as buttonCheck – (see full list of button objects below).

用法:
三个可用按钮对象之一可与此方法一起使用,如下所示:

按钮

命令

buttonCheck

brain.buttonCheck.pressed(callback, arg) — The Check button

buttonLeft

brain.buttonLeft.pressed(callback, arg) — The Left button

buttonRight

brain.buttonRight.pressed(callback, arg) — The Right button

参数

描述

callback

先前定义的在按下指定按钮时执行的 函数

arg

可选。包含要传递给回调函数的参数的元组。更多信息,请参阅带参数的函数](…/Logic/Functions.md#functions-with-parameters)。

# Turn in a circle when the left button
# is pressed
def button_pressed():
    drivetrain.turn_for(RIGHT, 360, DEGREES)

brain.buttonLeft.pressed(button_pressed)

released#

released registers a function to be called when a specific button on the Brain is released. This method must be called on a specific button object, such as buttonCheck – (see full list of button objects below).

用法:
三个可用按钮对象之一可与此方法一起使用,如下所示:

按钮

命令

buttonCheck

brain.buttonCheck.released(callback, arg) — The Check button

buttonLeft

brain.buttonLeft.released(callback, arg) — The Left button

buttonRight

brain.buttonRight.released(callback, arg) — The Right button

参数

描述

callback

先前定义的在释放指定按钮时执行的 函数

arg

可选。包含要传递给回调函数的参数的元组。更多信息,请参阅带参数的函数](…/Logic/Functions.md#functions-with-parameters)。

# Turn in a circle when the left button
# is released
def button_released():
    drivetrain.turn_for(LEFT, 360, DEGREES)

brain.buttonLeft.released(button_released)

吸气剂#

pressing#

pressing returns a Boolean indicating whether a specific button on the Brain is currently being pressed. This method must be called on a specific button object, such as buttonCheck (see full list of button objects below).

  • True - The specified button is being pressed.

  • False - The specified button is not being pressed.

用法:
三个可用按钮对象之一可与此方法一起使用,如下所示:

按钮

命令

buttonCheck

brain.buttonCheck.pressing() — The Check button

buttonLeft

brain.buttonLeft.pressing() — The Left button

buttonRight

brain.buttonRight.pressing() — The Right button

参数

描述

该方法没有参数。

# Turn when the check button is pressed
while True:
    if brain.buttonCheck.pressing():
        drivetrain.turn(RIGHT)
    else:
        drivetrain.stop()

capacity#

capacity returns the remaining capacity of the battery as a percentage.

Usage:
brain.battery.capacity()

参数

描述

该方法没有参数。

# Display the current battery capacity
brain.screen.print(brain.battery.capacity())

voltage#

voltage returns the voltage of the battery as a float.

Usage:
brain.battery.voltage(units)

参数

描述

units

Optional. The unit that represents the voltage:

  • MV (default) – Millivolts
  • VOLT

# Display the current voltage of the battery
brain.screen.print(brain.battery.voltage())

current#

current returns the current drawn from the battery in milliamps as a float.

Usage:
brain.battery.current()

参数

描述

该方法没有参数。

# Display the current of the battery
brain.screen.print(brain.battery.current())

构造函数#

Brain#

Brain creates an object of the brain class.

Usage:
brain = Brain()

参数

描述

该方法没有参数。

brain = Brain()

# Turn when the check button is pressed
while True:
    if brain.buttonCheck.pressing():
        drivetrain.turn(RIGHT)
    else:
        drivetrain.stop()