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 |
---|---|
|
El puerto de 3 cables al que está conectado el interruptor de parachoques, ya sea un puerto en el Cerebro o un Expandedor de 3 cables. |
Primero se debe crear un Brain o un 3-Wire Expander antes de poder usarlos para crear un objeto con el constructor de la clase 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.
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 |
---|---|
llamar de vuelta |
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 |
---|---|
llamar de vuelta |
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.