脑#

介绍#

VEX EXP 脑感应类别提供了与大脑的按钮和连接的电池进行交互的方法。

本页面使用 brain 作为示例大脑名称。您可以根据需要将其替换为您自己配置的名称。

以下是所有方法的列表:

获取器 — 返回来自电池和按钮的数据。

  • pressing — 返回指定的按钮是否被按下。

  • voltage — 返回电池电压。

  • current — 返回电池电流消耗。

  • capacity — 返回剩余电池容量。

回调函数 - 注册按钮按下或释放时要调用的函数。

  • pressed — 注册一个在按下指定按钮时要调用的函数。

  • released — 注册一个在指定按钮释放时要调用的函数。

获取器#

pressing#

pressing 返回一个布尔值,指示大脑上的特定按钮当前是否被按下。此方法必须在特定的按钮对象上调用,例如 buttonCheck (请参阅下面的完整按钮对象列表)。

  • True — 指定的按钮正在被按下。

  • False ​​— 指定的按钮未被按下。

用法:
此方法可以使用以下三种按钮对象之一:

按钮

命令

buttonCheck

brain.buttonCheck.pressing() — 勾选按钮

buttonLeft

brain.buttonLeft.pressing() — 左按钮

buttonRight

brain.buttonRight.pressing() — 右按钮

参数

描述

此方法没有参数。

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

voltage#

Voltage is the electrical pressure supplied to the battery. voltage returns the voltage of the battery as a decimal (float), which can help you check whether the battery is charged enough for the robot to run reliably, ranging from 7.0 to 8.0 Volts.

Usage:
brain.battery.voltage(units)

参数

描述

units

可选。电压单位: MV (默认)— 毫伏,或 VOLT

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

current#

电流表示机器人从电池消耗的电量。0 电流 current ,以十进制数 (float) 表示,这可以帮助您了解机器人的工作强度或电机是否可能承受额外负载,范围从 0.0 到 15.0 安培。

Usage:
brain.battery.current()

参数

描述

此方法没有参数。

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

capacity#

capacity 返回剩余电池电量,以百分比表示,范围从 0% 到 100%。

Usage:
brain.battery.capacity()

参数

描述

此方法没有参数。

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

回调函数#

pressed#

pressed 注册一个函数,当大脑上的特定按钮被按下时,该函数将被调用。此方法必须在特定的按钮对象上调用,例如 buttonCheck —(请参阅下面的按钮对象完整列表)。

用法:
此方法可以使用以下三种按钮对象之一:

按钮

命令

buttonCheck

brain.buttonCheck.pressed(callback, arg) — 选中按钮

buttonLeft

brain.buttonLeft.pressed(callback, arg) — 左按钮

buttonRight

brain.buttonRight.pressed(callback, arg) — 右按钮

参数

描述

callback

一个预先定义好的函数,当按下指定的按钮时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅带参数的函数。

# 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 注册一个函数,当 Brain 上的特定按钮被释放时,该函数将被调用。此方法必须在特定的按钮对象上调用,例如 buttonCheck —(请参阅下面的按钮对象完整列表)。

用法:
此方法可以使用以下三种按钮对象之一:

按钮

命令

buttonCheck

brain.buttonCheck.released(callback, arg) — 选中按钮

buttonLeft

brain.buttonLeft.released(callback, arg) — 左按钮

buttonRight

brain.buttonRight.released(callback, arg) — 右按钮

参数

描述

callback

一个预先定义好的函数,当指定的按钮被释放时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅带参数的函数。

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

brain.buttonLeft.released(button_released)