保险杠#

初始化保险杠类#

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

The bumper constructor creates a bumper object in the specified Three Wire Port:

范围

描述

port

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

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

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

类方法#

按下()#

The pressed(callback) method calls a function when the bumper switch is 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);
}

发布()#

The released(callback) method calls a function when the bumper switch is 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);
}

紧迫()#

The pressing() method gets the pressed status of the bumper device.

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

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

时间戳()#

The timestamp() method requests the timestamp of the last received status packet from the Bumper Sensor.

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

安装()#

The installed() method checks if the bumper device is installed.

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

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