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

port

Un Puerto inteligente válido al que está conectado el sensor de parachoques.

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

Métodos de clase#

apretado()#

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

Parámetro

Descripción

callback

Una referencia a una función.

Devoluciones: Ninguna.

// 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);
}

liberado()#

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

Parámetro

Descripción

callback

Una referencia a una función.

Devoluciones: Ninguna.

// 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);
}

prensado()#

The pressing() method gets the pressed status of the bumper device.

Devuelve: Un entero que representa el estado del dispositivo de parachoques. Si está presionado, devolverá uno; si no está presionado, devolverá cero.

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

marca de tiempo()#

The timestamp() method requests the timestamp of the last received status packet from the Bumper Sensor.

Devuelve: Marca de tiempo del último paquete de estado como un entero de 32 bits sin signo en milisegundos.

instalado()#

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

Devuelve: Un valor booleano que indica si el dispositivo de parachoques está instalado.

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