límite#

Inicializando la clase límite#

Un interruptor de límite se crea utilizando el siguiente constructor:

The limit constructor creates a limit object in the specified Three Wire Port.

Parámetro

Descripción

port

El puerto de 3 cables al que está conectado el interruptor de límite, 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 clase Limit.

// Create the Brain.
brain Brain;
// Construct a Limit Switch "limit" with the Limit class.
limit Limit = limit(Brain.ThreeWirePort.A);

This limit object will be used in all subsequent examples throughout this API documentation when referring to limit class methods.

Métodos de clase#

pressed()#

The pressed(callback) command registers a callback function for when the Limit Switch is pressed.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando se presione el interruptor de límite.

Devoluciones: Ninguna.

// Define the switchPressed function with a void return type,
// showing it doesn't return a value.
void switchPressed() {
  // The Brain will print that the Limit Switch was pressed
  // on the Brain's screen.
  Brain.Screen.print("switch pressed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run switchPressed when the Limit Switch is pressed.
  Limit.pressed(switchPressed);
}

released()#

The released(callback) command registers a callback function for when the Limit Switch is released.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando se libere el interruptor de límite.

Devoluciones: Ninguna.

// Define the switchReleased function with a void return
// type, showing it doesn't return a value.
void switchReleased() {
  // The Brain will print that the Limit Switch was released
  // on the Brain's screen.
  Brain.Screen.print("switch released");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run switchReleased when the Limit Switch is released.
  LimitSwitchA.released(switchReleased);
}

pressing()#

The pressing() command checks if the Limit 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.