保险杠开关#
介绍#
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); }