Limit Switch#

Introduction#

The limit class is used to detect when the Limit Switch is pressed and released.

Class Constructor#

limit(
  triport::port &port);

Class Destructor#

Destroys the limit object and releases associated resources.

virtual ~limit();

Parameters#

Parameter

Type

Description

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

Example#

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

Member Functions#

The limit class includes the following member functions:

  • pressing — Returns a Boolean indicating whether the Limit Switch is being pressed.

  • pressed — Registers a function to be called when the Limit Switch is pressed.

  • released — Registers a function to be called when 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#

Returns if the Limit Switch is currently being pressed.

Available Functions
int32_t pressing();

Parameters

This function does not accept any parameters.

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#

Registers a function to be called when the Limit Switch is pressed.

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

Parameters

Parameter

Type

Description

callback

void (*)(void)

A pointer to a function that will be called when the bumper is pressed. The function must take no parameters and return void.

Return Values

This function does not return a value.

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

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

released#

Registers a function to be called when the Limit Switch is released.

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

Parameters

Parameter

Type

Description

callback

void (*)(void)

A pointer to a function that will be called when the bumper is released. The function must take no parameters and return void.

Return Values

This function does not return a value.

Examples
void switchReleased() {
  Brain.Screen.print("switch released");
}

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