バンパースイッチ#

導入#

bumper クラスは、バンパースイッチが押されたときと離されたときを検出するために使用されます。

クラスコンストラクタ#

bumper( 
  int32_t index );

クラスデストラクタ#

bumper オブジェクトを破壊し、関連するリソースを解放します。

virtual ~bumper();

パラメータ#

パラメータ

タイプ

説明

index

int32_t

バンパースイッチが接続されているスマートポートは、 PORTxと表記され、 x はポート番号です (例: PORT1)。

例#

// Create a bumper instance in Port 1
bumper Bumper1 = bumper(PORT1);

メンバーの機能#

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

  • pressing押す — バンパースイッチが押されている場合は戻ります。

  • pressed — バンパースイッチが押されたときに呼び出される関数を登録します。

  • released — バンパースイッチが離されたときに呼び出される関数を登録します。

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

/* This constructor is required when using VS Code.
Bumper Switch configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create a bumper instance in Port 1
bumper Bumper1 = bumper(PORT1);

pressing#

バンパースイッチが現在押されている場合は戻ります。

Available Functions
int32_t pressing();

Parameters

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

Return Values

バンパースイッチが押されているかどうかを示す int32_t を返します。

  • 1 — バンパースイッチが押されています。

  • 0 — バンパースイッチが押されていません。

pressed#

バンパースイッチが押されたときに呼び出される関数を登録します。

Available Functions
void pressed( void (* callback)(void) );

Parameters

パラメータ

タイプ

説明

callback

void (*)(void)

バンパーが押されたときに呼び出される関数へのポインタ。この関数は引数を取らず、戻り値はvoidでなければなりません。

Return Values

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

Examples

コールバック関数を定義します( int main()の外側)

// Display a message when bumper is pressed
void BumperPressed() {
  Brain.Screen.print("Bumper pressed");
}

コールバックを登録する int main()

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

  // Run BumperPressed when the value of the Bumper Switch is pressed.
  Bumper1.pressed(BumperPressed);
}

released#

バンパースイッチが離されたときに呼び出される関数を登録します。

Available Functions
void released( void (* callback)(void) );

Parameters

パラメータ

タイプ

説明

callback

void (*)(void)

バンパーが離されたときに呼び出される関数へのポインタ。この関数は引数を取らず、戻り値はvoidでなければなりません。

Return Values

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

Examples

コールバック関数を定義します( int main()の外側)

// Display a message when bumper is released
void BumperReleased() {
  Brain.Screen.print("Bumper released");
}

コールバックを登録する int main()

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

  // Run BumperReleased when the value of the Bumper Switch is released.
  Bumper1.released(BumperReleased);
}