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 |
---|---|
|
The 3-Wire Port that the Bumper Switch is connected to, whether it’s a port on the Brain, or a 3-Wire Expander. |
A Brain or 3-Wire Expander must be created first before they can be used to create an object with the Bumper Class constructor.
// 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.
Class Methods#
pressed()#
The pressed(callback)
method registers a function to be called when the Bumper Switch is pressed.
Parameters |
Description |
---|---|
callback |
A function that will be called when the Bumper is pressed. |
Returns: An instance of the Event class.
// 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.
Parameters |
Description |
---|---|
callback |
A function that will be called when the Bumper is released. |
Returns: An instance of the Event class.
// 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.