保險桿開關#
介紹#
bumper 類用於檢測保險桿開關何時被按下和釋放。
類別建構函數#
bumper(
int32_t index );
類別析構函數#
銷毀 bumper 對象並釋放相關資源。
virtual ~bumper();
參數#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
保險桿開關所連接的智慧型端口,記為 |
例子#
// Create a bumper instance in Port 1
bumper Bumper1 = bumper(PORT1);
成員功能#
bumper 類包含以下成員函數:
在呼叫任何 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); }