限制#

初始化限制类#

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

limit 构造函数在指定的三线端口中创建一个限制对象。

范围

描述

端口

限位开关连接到的 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);

当引用限制类方法时,此“limit”对象将在整个 API 文档的所有后续示例中使用。

类方法#

按下()#

pressed(callback) 命令注册限位开关被按下时的回调函数。

参数

描述

打回来

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

**返回:**无。

// 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(callback) 命令注册限位开关释放时的回调函数。

参数

描述

打回来

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

**返回:**无。

// 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() 命令检查限位开关当前是否被按下。

**返回值:**表示保险杠开关状态的整数值。如果保险杠开关被按下,则返回“1”。如果没有按下,则返回“0”。