保险杠#

初始化保险杠类#

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

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

范围

描述

port

保险杠开关所连接的 3 线端口,无论它是 大脑 上的端口,还是 3 线扩展器 上的端口。

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

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

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

类方法#

pressed()#

The pressed(callback) method registers a function to be called when the Bumper Switch is pressed.

参数

描述

打回来

当保险杠被按下时将调用的函数。

**返回:**事件类的一个实例。

// 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()#

The released(callback) method registers a function to be called when the Bumper Switch is released.

参数

描述

打回来

当保险杠被释放时将调用的函数。

**返回:**事件类的一个实例。

// 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()#

The pressing() method checks if the Bumper 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.