Interruptor de límite#

Introducción#

The limit class is used with the Limit Switch, a small digital sensor that detects physical contact with an object.

El interruptor de límite VEX EXP.

Constructor de clases#

limit(
  triport::port &port);

Instructor de clase#

Destroys the limit object and releases associated resources.

virtual ~limit();

Parámetros#

Parámetro

Tipo

Descripción

port

triport::port &

The 3-Wire Port that the Limit Switch is connected to, written as Brain.ThreeWirePort.X or ExpanderName.X, where X is the port letter (for example, Brain.ThreeWirePort.A or Expander1.A).

Ejemplo#

// Create a limit instance in Port A
limit LimitSwitchA = limit(Brain.ThreeWirePort.A);

Funciones de los miembros#

The limit class includes the following member functions:

  • pressing – Returns whether the Limit Switch is being pressed.

  • pressed – Registers a function to be called whenever the Limit Switch is pressed.

  • released – Registers a function to be called whenever the Limit Switch is released.

Before calling any limit member functions, a limit instance must be created, as shown below:

/* This constructor is required when using VS Code.
Limit Switch configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create a limit instance in Port A
limit LimitSwitchA = limit(Brain.ThreeWirePort.A);

pressing#

Indica si el interruptor de límite está presionado. Esto permite comprobar si el robot choca con otros objetos.

Available Functions
int32_t pressing();

Parameters

Esta función no acepta ningún parámetro.

Return Values

Returns an int32_t indicating whether the Limit Switch is being pressed.

  • 1 — The Limit Switch is being pressed.

  • 0 — The Limit Switch is not being pressed.

pressed#

Registra una función que se llamará cuando se presione el interruptor de límite.

Available Functions
void pressed(
  void (* callback)(void) );

Parameters

Parámetro

Tipo

Descripción

callback

void (*)(void)

Un puntero a una función que se llamará cuando se presione el interruptor de límite.

Return Values

Esta función no devuelve ningún valor.

Examples

Define the callback function (outside of int main())

void switchPressed() {
  // The Brain will print that the Limit Switch was pressed
  // on the Brain's screen.
  Brain.Screen.print("switch pressed");
}

Register the callback inside int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

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

released#

Registra una función que se llamará cuando se suelte el interruptor de límite.

Available Functions
void released(
  void (* callback)(void) );

Parameters

Parámetro

Tipo

Descripción

callback

void (*)(void)

Un puntero a una función que se llamará cuando se suelte el interruptor de límite.

Return Values

Esta función no devuelve ningún valor.

Examples

Define the callback function (outside of int main())

void switchReleased() {
  // The Brain will print that the Limit Switch was released
  // on the Brain's screen.
  Brain.Screen.print("switch released");
}

Register the callback inside int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

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