限位开关#

介绍#

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();

参数#

范围

类型

描述

port

triport::port &

The 3-Wire Port that the Limit Switch is connected to, written as Brain.ThreeWirePort.X or ExpanderName.X, where X is the port letter (for example, Brain.ThreeWirePort.A or Expander1.A).

例子#

// 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 Functions
int32_t pressing();

Parameters

此函数不接受任何参数。

Return Values

Returns 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 Functions
void pressed( 
  void (* callback)(void) );

Parameters

范围

类型

描述

callback

void (*)(void)

指向一个函数的指针,该函数将在限位开关按下时调用。该函数不得接受任何参数,且必须返回 void 值。

Return Values

此函数不返回值。

Examples
void 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 Functions
void released( 
  void (* callback)(void) );

Parameters

范围

类型

描述

callback

void (*)(void)

指向一个函数的指针,该函数将在限位开关释放时被调用。该函数不能接受任何参数,并且必须返回 void。

Return Values

此函数不返回值。

Examples
void switchReleased() {
  Brain.Screen.print("switch released");
}

// Run switchReleased when the Limit Switch is released.
LimitSwitchA.released(switchReleased);