タイマー#
導入#
VEX IQ(第2世代)のタイマー機能を使用すると、経過時間を追跡し、時間間隔に基づいてアクションを実行できます。これは、何かにかかる時間を測定したり、新しいタイミング操作のためにリセットしたりするのに使用できます。
以下にすべてのメソッドの一覧を示します。
方法 ― 脳のタイマーを制御し、操作する。
time— 経過した時間を返します。clear— タイマーをゼロにリセットします。system— Brain の電源がオンになってからのミリ秒数を返します。system_high_res— Brain の電源がオンになっているマイクロ秒数を返します。event— 指定されたミリ秒数後に呼び出される関数を登録します。
コンストラクタ — 追加のタイマーを作成します。
Timer— 追加のタイマーを作成します。
時間#
time は、タイマーが最後にリセットされてからの時間を小数で返します。タイマーはプロジェクトの開始時に自動的にリセットされます。
Usage:
brain.timer.time(units)
パラメータ |
説明 |
|---|---|
|
時間を表す単位: |
# Display the current time on the timer
while True:
brain.screen.set_cursor(1, 1)
brain.screen.clear_screen()
brain.screen.print(brain.timer.time(SECONDS))
wait(50, MSEC)
クリア#
clear タイマーをゼロに設定します。これは、同じプロジェクト内の他のコードセクションの時間を計測するために使用できます。
Usage:
brain.timer.clear()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
# Reset the timer when a button is pressed
while True:
brain.screen.set_cursor(1, 1)
brain.screen.clear_screen()
brain.screen.print(brain.timer.time(SECONDS))
wait(50, MSEC)
if brain.buttonCheck.pressing():
brain.timer.clear()
システム#
system 、脳 の電源がオンになってからのミリ秒数を返します。
Usage:
brain.timer.system()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
# Display the time the brain has been on in milliseconds
while True:
brain.screen.set_cursor(1, 1)
brain.screen.clear_screen()
brain.screen.print(brain.timer.system())
brain.screen.print(" MSEC")
wait(50, MSEC)
システム高解像度#
system_high_res は、brain の電源がオンになっているマイクロ秒数を返します。
Usage:
brain.timer.system_high_res()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
# Display the time the brain has been on in microseconds
while True:
brain.screen.set_cursor(1, 1)
brain.screen.clear_screen()
brain.screen.print(brain.timer.system_high_res())
wait(50, MSEC)
イベント#
event は、指定された時間が経過した後に関数を呼び出します。
Usage:
brain.timer.event(callback, delay, arg)
パラメータ |
説明 |
|---|---|
|
タイマーイベントが発生したときに実行される関数。 |
|
関数が呼び出されるまでの遅延時間(ミリ秒単位)。 |
|
オプション。コールバック関数に渡す引数を含むタプル。詳細については、パラメータを持つ関数を参照してください。 |
# Define a function timer_event
def timer_event():
drivetrain.drive_for(FORWARD, 200, MM)
# Drive forward after a 5000 millisecond delay
brain.timer.event(timer_event, 5000)
建設業者#
コンストラクタは、手動で Timer オブジェクトを作成するために使用されます。これは、 brain.timer以外の追加のタイマーを作成するために必要なものです。
For the examples below, the configured Timer will be named timer_1 and will be used in all subsequent examples throughout this API documentation when referring to Timer class methods.
Timer#
Timer は新しいタイマーを作成します。2 Timer オブジェクトは作成された瞬間にカウントを開始し、すべての brain.timer メソッドで動作します。
Usage:
Timer()
パラメータ |
説明 |
|---|---|
このコンストラクタにはパラメータがありません。 |
wait(2, SECONDS)
timer_1 = Timer()
while True:
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Brain: ")
brain.screen.print(brain.timer.time(SECONDS))
brain.screen.next_row()
brain.screen.print("timer_1: ")
brain.screen.print(timer_1.time(SECONDS))
wait(15, MSEC)