保险杠#

初始化保险杠类#

使用以下构造函数创建 Bumper Switch:

bumper 构造函数在指定的三线端口中创建一个 bumper 对象:

范围

描述

端口

保险杠传感器连接到的有效 智能端口

// Create the Brain.
brain Brain;
// Construct a Bumper Switch "BumperA" with the
// bumper class.
bumper BumperA = bumper();

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

类方法#

按下()#

当保险杠开关被按下时,pressed(callback) 方法调用一个函数。

范围

描述

回调

对函数的引用。

**返回:**无。

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

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

  // Run BumperPressed when the value of the Bumper Switch is pressed.
  BumperA.pressed(BumperPressed);
}

发布()#

当保险杠开关被释放时,released(callback) 方法调用一个函数。

范围

描述

回调

对函数的引用。

**返回:**无。

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

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

  // Run bumperReleased when the value of the Bumper Switch is released.
  BumperA.released(bumperReleased);
}

紧迫()#

pressing() 方法获取保险杠设备的按下状态。

**返回值:**一个整数,表示保险杠设备的状态。如果按下,则返回 1;如果未按下,则返回 0。

// Get the pressed status of the bumper device.
int32_t pressedStatus = BumperA.pressing();

时间戳()#

timestamp() 方法请求保险杠传感器最后接收到的状态包的时间戳。

**返回:**最后一个状态包的时间戳,以毫秒为单位的无符号 32 位整数。

安装()#

installed() 方法检查保险杠设备是否已安装。

**返回:**一个布尔值,指示保险杠装置是否已安装。

// Check if the bumper device is installed.
bool isInstalled = BumperA.installed();