リミットスイッチ#
導入#
limit クラスは、物体との物理的な接触を検出する小型デジタルセンサーであるリミットスイッチで使用されます。

クラスコンストラクタ#
limit(
triport::port &port);
クラスデストラクタ#
limit オブジェクトを破棄し、関連するリソースを解放します。
virtual ~limit();
パラメータ#
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
リミットスイッチが接続されている3線式ポートは、 |
例#
// Create a limit instance in Port A
limit LimitSwitchA = limit(Brain.ThreeWirePort.A);
メンバーの機能#
limit クラスには、以下のメンバ関数が含まれています。
pressingを押している – リミットスイッチが押されているかどうかを返します。pressed– リミットスイッチが押されたときに呼び出される関数を登録します。released– リミットスイッチが解放されるたびに呼び出される関数を登録します。
limit を呼び出す前に、以下に示すように limit 作成する必要があります。
/* This constructor is required when using VS Code.
Limit Switch configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a limit instance in Port A
limit LimitSwitchA = limit(Brain.ThreeWirePort.A);
pressing#
リミットスイッチが現在押されているかどうかを返します。これは、ロボットが他の物体に衝突したかどうかを確認するために使用できます。
Available Functionsint32_t pressing();
この関数は引数を受け付けません。
Return Valuesリミットスイッチが押されているかどうかを示す int32_t を返します。
1— リミットスイッチが押されています。0— リミットスイッチが押されていません。
pressed#
リミットスイッチが押されたときに呼び出される関数を登録します。
Available Functionsvoid pressed(
void (* callback)(void) );
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
リミットスイッチが押されたときに呼び出される関数へのポインタ。 |
この関数は値を返しません。
Examplesコールバック関数を定義します(
int main()の外側)void switchPressed() { // The Brain will print that the Limit Switch was pressed // on the Brain's screen. Brain.Screen.print("switch pressed"); }コールバックを登録する
int main()int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run switchPressed when the Limit Switch is pressed. LimitSwitchA.pressed(switchPressed); }
released#
リミットスイッチが解除されたときに呼び出される関数を登録します。
Available Functionsvoid released(
void (* callback)(void) );
パラメータ |
タイプ |
説明 |
|---|---|---|
|
|
リミットスイッチが解除されたときに呼び出される関数へのポインタ。 |
この関数は値を返しません。
Examplesコールバック関数を定義します(
int main()の外側)void switchReleased() { // The Brain will print that the Limit Switch was released // on the Brain's screen. Brain.Screen.print("switch released"); }コールバックを登録する
int main()int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run switchReleased when the Limit Switch is released. LimitSwitchA.released(switchReleased); }