parachoques#
Inicializando la clase bumper#
Un interruptor de parachoques se crea utilizando el siguiente constructor:
The bumper constructor creates a bumper object in the specified Three Wire Port:
Parámetro |
Descripción |
|---|---|
|
The 3-Wire Port that the Bumper Switch is connected to, whether it’s a port on the |
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.
Métodos de clase#
pressed()#
The pressed(callback) method registers a function to be called when the Bumper Switch is pressed.
Parámetros |
Descripción |
|---|---|
|
Una función que se llamará cuando se presione el parachoques. |
Devuelve: Una instancia de la clase Event.
// 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.
Parámetros |
Descripción |
|---|---|
|
Una función que se llamará cuando se suelte el parachoques. |
Devuelve: Una instancia de la clase Event.
// 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.