限位开关#
介绍#
The limit class is used to detect when the Limit Switch is pressed and released.
类构造函数#
limit(
triport::port &port);
类析构函数#
Destroys the limit object and releases associated resources.
virtual ~limit();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
The 3-Wire Port that the Limit Switch is connected to, written as |
例子#
// Create a limit instance in Port A
limit LimitSwitchA = limit(Brain.ThreeWirePort.A);
成员功能#
The limit class includes the following member functions:
pressing— Returns a Boolean indicating whether the Limit Switch is being pressed.pressed— Registers a function to be called when the Limit Switch is pressed.released— Registers a function to be called when the Limit Switch is released.
Before calling any limit member functions, a limit instance must be created, as shown below:
/* 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 ValuesReturns an int32_t indicating whether the Limit Switch is being pressed.
1— The Limit Switch is being pressed.0— The Limit Switch is not being pressed.
pressed#
注册一个在按下限位开关时要调用的函数。
Available Functionsvoid pressed(
void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
指向一个函数的指针,该函数将在限位开关按下时调用。该函数不得接受任何参数,且必须返回 void 值。 |
此函数不返回值。
Examplesvoid switchPressed() {
// The Brain will print that the Limit Switch was pressed
// on the Brain's screen.
Brain.Screen.print("switch pressed");
}
// Run switchPressed when the Limit Switch is pressed.
LimitSwitchA.pressed(switchPressed);
released#
注册一个在限位开关释放时要调用的函数。
Available Functionsvoid released(
void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
指向一个函数的指针,该函数将在限位开关释放时被调用。该函数不能接受任何参数,并且必须返回 void。 |
此函数不返回值。
Examplesvoid switchReleased() {
Brain.Screen.print("switch released");
}
// Run switchReleased when the Limit Switch is released.
LimitSwitchA.released(switchReleased);