タイマー#

導入#

VEX 123のタイマー機能を使うと、経過時間を追跡し、時間間隔に基づいて動作を実行できます。何かにかかる時間を計測したり、新しいタイミング操作のためにリセットしたりするのに使用できます。

以下にすべてのメソッドの一覧を示します。

メソッド – タイマーの制御と操作

  • reset – タイマーをゼロにリセットします。

  • time – 経過した時間を返します。

コンストラクタ – 追加のタイマーを作成します。

  • Timer – 追加のタイマーを作成します。

リセット#

reset はタイマーをゼロに設定します。これは、同じプロジェクト内の他のコードセクションの時間を計測するために使用できます。

Usage:
timer.reset()

パラメータ

説明

このメソッドにはパラメータがありません。

# Reset the timer when the Move button is pressed
while True:
    console.clear()
    console.print(timer.time(SECONDS))
    wait(50, MSEC)
    if robot.get_button(MOVE):
        timer.reset()

時間#

time は、タイマーが最後にリセットされてからの時間を小数で返します。タイマーはプロジェクトの開始時に自動的にリセットされます。

Usage:
timer.time(units)

パラメータ

説明

units

時間を表す単位: MSEC (デフォルト) – ミリ秒、または SECONDS

# Display the time until the Move button is pressed
while True:
    console.clear()
    console.print(timer.time(SECONDS))
    wait(50, MSEC)
    if robot.get_button(MOVE):
        timer.reset()

建設業者#

Timer#

Timer は新しいタイマーを作成します。 Timer オブジェクトは作成された瞬間にカウントを開始し、すべての timer メソッドで動作します。

Usage:
my_timer = Timer()

パラメータ

説明

このコンストラクタにはパラメータがありません。

# Display the time of two timers
wait(2, SECONDS)
timer_1 = Timer()
while True:
    console.clear()
    console.print("Timer: ", timer.time(SECONDS))
    console.new_line()
    console.print("timer_1: ", timer_1.time(SECONDS))
    wait(15, MSEC)