限位開關#
介紹#
limit 類與限位開關一起使用,限位開關是一種小型數位感測器,用於偵測與物體的物理接觸。

類別建構函數#
limit(
triport::port &port);
類別析構函數#
銷毀 limit 物件並釋放相關資源。
virtual ~limit();
參數#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
限位開關連接的 3 線端口,寫成 |
例子#
// Create a limit instance in Port A
limit LimitSwitchA = limit(Brain.ThreeWirePort.A);
成員功能#
limit 類別包含以下成員函數:
在呼叫任何 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); }