腦#
介紹#
VEX EXP 腦感應類別提供了與大腦的按鈕和連接的電池互動的方法。
本頁面使用 brain 作為範例大腦名稱。您可以根據需要將其替換為您自己配置的名稱。
以下是所有方法的清單:
獲取器 — 傳回來自電池和按鈕的資料。
回調函數 - 註冊按鈕按下或釋放時要呼叫的函數。
獲取器#
pressing#
pressing 返回一個布林值,指示大腦上的特定按鈕目前是否被按下。此方法必須在特定的按鈕物件上調用,例如 buttonCheck (請參閱下面的完整按鈕物件清單)。
True— 指定的按鈕正在被按下。False— 指定的按鈕未按下。
用法:
此方法可以使用以下三種按鈕物件之一:
按鈕 |
命令 |
|---|---|
|
|
|
|
|
|
參數 |
描述 |
|---|---|
此方法沒有參數。 |
# 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)
參數 |
描述 |
|---|---|
|
可選。電壓單位: |
# 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 —(請參閱下面的按鈕物件完整清單)。
用法:
此方法可以使用以下三種按鈕物件之一:
按鈕 |
命令 |
|---|---|
|
|
|
|
|
|
參數 |
描述 |
|---|---|
|
一個預先定義好的函數,當按下指定的按鈕時執行。 |
|
# 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 —(請參閱下面的按鈕物件完整清單)。
用法:
此方法可以使用以下三種按鈕物件之一:
按鈕 |
命令 |
|---|---|
|
|
|
|
|
|
參數 |
描述 |
|---|---|
|
一個預先定義好的函數,當指定的按鈕被釋放時執行。 |
|
# Turn in a circle when the left button
# is released
def button_released():
drivetrain.turn_for(LEFT, 360, DEGREES)
brain.buttonLeft.released(button_released)