bumper#

Initializing the bumper Class#

A Bumper Sensor 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 Sensor "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 Sensor 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 Sensor 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 Sensor 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 Sensor is released.
  BumperA.released(bumperReleased);
}

pressing()#

The pressing() method gets the pressed status of the Bumper Sensor.

Returns: An integer representing the state of the Bumper Sensor. If it is pressed, it will return 1; if unpressed, it will return 0.

// Get the pressed status of the Bumper Sensor.
int32_t pressedStatus = BumperA.pressing();

installed()#

The installed() method checks if the Bumper Sensor is installed.

Returns: true if the Bumper Sensor is installed. false if it is not.

// Check if the Bumper Sensor is installed.
bool isInstalled = BumperA.installed();