バンパースイッチ#
導入#
bumper クラスは、バンパースイッチが押されたときと離されたときを検出するために使用されます。
クラスコンストラクタ#
bumper(
int32_t index );
クラスデストラクタ#
bumper オブジェクトを破壊し、関連するリソースを解放します。
virtual ~bumper();
パラメータ#
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
バンパースイッチが接続されているスマートポートは、 |
例#
// 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 Functionsint32_t pressing();
この関数は引数を受け付けません。
Return Valuesバンパースイッチが押されているかどうかを示す int32_t を返します。
1— バンパースイッチが押されています。0— バンパースイッチが押されていません。
pressed#
バンパースイッチが押されたときに呼び出される関数を登録します。
Available Functionsvoid pressed( void (* callback)(void) );
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
バンパーが押されたときに呼び出される関数へのポインタ。この関数は引数を取らず、戻り値はvoidでなければなりません。 |
この関数は値を返しません。
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 Functionsvoid released( void (* callback)(void) );
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
バンパーが離されたときに呼び出される関数へのポインタ。この関数は引数を取らず、戻り値はvoidでなければなりません。 |
この関数は値を返しません。
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); }