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

The 3-Wire Port that the Limit 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 Limit Class constructor.

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

callback

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

callback

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.