bumper#

Initializing the bumper Class#

A Bumper Switch is created by using the following constructor:

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

Parameter

Description

port

A valid Smart Port that the Bumper Sensor is connected to.

// 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.

Class Methods#

pressed()#

The pressed(callback) method calls a function when the bumper switch is pressed.

Parameter

Description

callback

A reference to a function.

Returns: None.

// 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 calls a function when the bumper switch is released.

Parameter

Description

callback

A reference to a function.

Returns: None.

// 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 gets the pressed status of the bumper device.

Returns: An Integer representing the state of the bumper device. If it is pressed, it will return one; if unpressed, it will return zero.

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

installed()#

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

Returns: A bool indicating whether the bumper device is installed.

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