保险杠开关#
介绍#
The bumper class is used to detect when the Bumper Switch is pressed and released.
类构造函数#
bumper(
triport::port &port );
类析构函数#
Destroys the bumper object and releases associated resources.
virtual ~bumper();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
The 3-Wire Port that the Bumper Switch is connected to, written as |
例子#
// Create a bumper instance in Port A
bumper BumperA = bumper(Brain.ThreeWirePort.A);
成员功能#
The bumper class includes the following member functions:
pressing— Returns if the Bumper Switch is being pressed.pressed— Registers a function to be called when the Bumper Switch is pressed.released— Registers a function to be called when the Bumper Switch is released.
Before calling any bumper member functions, a bumper instance must be created, as shown below:
/* 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 A
bumper BumperA = bumper(Brain.ThreeWirePort.A);
pressing#
如果当前按下保险杠开关,则返回。
Available Functionsint32_t pressing();
此函数不接受任何参数。
Return ValuesReturns an int32_t indicating whether the Bumper Switch is being pressed.
1— The Bumper Switch is being pressed.0— The Bumper Switch is not being pressed.
pressed#
注册一个在按下保险杠开关时要调用的函数。
Available Functionsvoid pressed( void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
指向一个函数的指针,该函数将在按下保险杠时调用。该函数不能接受任何参数,并且必须返回 void。 |
此函数不返回值。
Examplesvoid BumperPressed() {
Brain.Screen.print("Bumper pressed");
}
// Run BumperPressed when the value of the Bumper Switch is pressed.
BumperA.pressed(BumperPressed);
released#
注册一个在释放碰撞开关时要调用的函数。
Available Functionsvoid released( void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
指向一个函数的指针,该函数将在保险杠释放时调用。该函数不能接受任何参数,并且必须返回 void。 |
此函数不返回值。
Examplesvoid BumperReleased() {
Brain.Screen.print("Bumper released");
}
// Run BumperReleased when the value of the Bumper Switch is released.
BumperA.released(BumperReleased);