タイマー#

導入#

timer クラスは、Brain のタイマー とは独立して時間を管理し、タイマーとやり取りするために使用されます。

クラスコンストラクタ#

timer();

クラスデストラクタ#

タイマー timer オブジェクトを破棄し、関連するリソースを解放します。

~timer();

パラメータ#

このコンストラクタはパラメータを受け付けません。

例#

// Create a timer instance
timer myTimer = timer();

メンバーの機能#

timer クラスには、以下のメンバ関数が含まれています。

  • reset — Resets the timer to zero.

  • value — Returns the elapsed time since the timer started.

  • event — 指定されたミリ秒数後に、オプションの引数とともに関数を呼び出します。

タイマー timer メンバ関数を呼び出す前に、以下に示すように timer インスタンスを作成する必要があります。

/* This constructor is required to use a 
custom timer. Replace the values
as needed. */

// Create a timer instance
timer myTimer = timer();

/* This constructor is required when using VS Code.
A Brain is generated automatically at the start of
VEXcode projects. */

// Create the Brain to use Brain.Timer
brain Brain = brain();

reset#

タイマーをゼロに設定します。

Available Functions
void reset();

Parameters

この関数は引数を受け付けません。

Return Values

この関数は値を返しません。

Examples
while (true) {
  // Clear the timer every time the screen is pressed
  if (Brain.Screen.pressing()) {
    myTimer.reset();
  }
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Time: %.2f", myTimer.value());
  wait(50, msec);
}

value#

タイマーの現在の値を返します。

Available Functions
double value();

Parameters

この関数は引数を受け付けません。

Return Values

経過時間を秒単位で表したdouble型の値。

Notes
  • タイマーは、タイマーが構築された時点でカウントを開始します。

  • Calling reset resets the timer value to zero.

Examples
// Display the timer as it ticks up
while (true) {
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Time: %.2f", myTimer.value());

  wait(50, msec);
}

event#

指定された遅延時間後に実行されるコールバック関数を登録します。

Available Functions

1 — 指定された遅延後に実行されるコールバックを登録し、ユーザー定義の値をコールバックに渡します。

static void event(
    void (*callback)(void *),
    uint32_t value );

2 — 指定された遅延後に実行されるコールバックを登録します。

static void event(
    void (*callback)(void),
    uint32_t value );

Parameters

パラメータ

タイプ

説明

callback

void (*)(void *)

指定された遅延時間の後に呼び出され、ユーザー定義の引数を受け取る関数。

callback

void (*)(void)

指定された遅延時間後に呼び出される関数。

value

uint32_t

コールバック関数が実行されるまでの時間(ミリ秒単位)。

Return Values

この関数は値を返しません。

Notes
  • この関数は一度限りのコールバックをスケジュールします。自動的に繰り返されることはありません。

  • コールバック関数は voidを返す必要があります。

  • 複数のイベントが同時に開催される場合があります。

Examples

関数を定義します ( int main()の外側)

// Create a function to turn the screen orange
void turnOrange() {
  Brain.Screen.clearScreen(orange);
}

関数を登録する int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  timer myTimer = timer();
  // Call turnOrange after 2 seconds
  myTimer.event(turnOrange, 2000);
}