限制#

初始化限制类#

使用以下构造函数创建限位开关:

The limit constructor creates a limit object in the specified Three Wire Port.

范围

描述

port

限位开关连接到的 3 线端口,无论它是 大脑 上的端口,还是 3 线扩展器 上的端口。

必须先创建 Brain3-Wire Expander,然后才能使用 Limit Class 构造函数创建对象。

// Create the Brain.
brain Brain;
// Construct a Limit Switch "limit" with the Limit class.
limit Limit = limit(Brain.ThreeWirePort.A);

This limit object will be used in all subsequent examples throughout this API documentation when referring to limit class methods.

类方法#

pressed()#

The pressed(callback) command registers a callback function for when the Limit Switch is pressed.

参数

描述

打回来

按下限位开关时调用的回调函数。

**返回:**无。

// Define the switchPressed function with a void return type,
// showing it doesn't return a value.
void switchPressed() {
  // The Brain will print that the Limit Switch was pressed
  // on the Brain's screen.
  Brain.Screen.print("switch pressed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run switchPressed when the Limit Switch is pressed.
  Limit.pressed(switchPressed);
}

released()#

The released(callback) command registers a callback function for when the Limit Switch is released.

参数

描述

打回来

当限位开关被释放时调用的回调函数。

**返回:**无。

// Define the switchReleased function with a void return
// type, showing it doesn't return a value.
void switchReleased() {
  // The Brain will print that the Limit Switch was released
  // on the Brain's screen.
  Brain.Screen.print("switch released");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

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

pressing()#

The pressing() command checks if the Limit Switch is currently being pressed.

Returns: An integer value representing the state of the Bumper Switch. A 1 is returned if the Bumper Switch is being pressed. A 0 will be returned if it is not.