定時器#
介紹#
VEX V5 中的計時器可讓您追蹤經過的時間並根據時間間隔執行操作。它可用於測量某項任務所需的時間,或重設計時器以進行新的計時操作。
此頁面使用 brain.timer 作為大腦計時器。您也可以建構 Timer 物件來建立一個新的計時器,並根據需要將其替換為您自己配置的名稱。
以下是所有方法的清單:
方法-控制並與大腦的計時器互動。
建構函式 – 建立額外的計時器。
Timer– 建立一個額外的定時器。
清除#
clear 將計時器設為零。這可用於對同一專案中的其他程式碼段進行計時。
Usage:
brain.timer.clear()
參數 |
描述 |
|---|---|
此方法沒有參數。 |
# Reset the timer when the Bumper Switch is pressed
while True:
print("\033[2J")
print(brain.timer.time(SECONDS))
wait(50, MSEC)
if bumper_switch.pressing():
brain.timer.clear()
時間#
time 傳回自上次計時器重設以來經過的時間,以十進位數表示。計時器會在專案開始時自動重設。
Usage:
brain.timer.time(units)
參數 |
描述 |
|---|---|
|
時間單位: |
# Display the time until the Bumper Switch is pressed
while True:
print("\033[2J")
print(brain.timer.time(SECONDS))
wait(50, MSEC)
if bumper_switch.pressing():
brain.timer.clear()
事件#
事件event
Usage:
brain.timer.event(callback, delay, arg)
參數 |
描述 |
|---|---|
|
當定時器事件發生時要執行的函數。 |
|
函數呼叫前的延遲時間,以毫秒為單位。 |
|
可選。包含要傳遞給回呼函數的參數的元組。有關更多信息,請參閱使用帶參數的函數。 |
def timer_event():
drivetrain.drive_for(FORWARD, 200, MM)
# Drive forward after a 5000 millisecond delay
brain.timer.event(timer_event, 5000)
建構函數#
Timer#
Timer 創造一個新的計時器。 2 Timer 物件會在創建後立即開始計時,並且可以與所有 timer 方法一起使用。
Usage:
Timer
參數 |
描述 |
|---|---|
此建構函數沒有參數。 |
# Create a Timer
timer = Timer()