limit#

Initializing the limit Class#

A Limit Switch is created by using the following constructor:

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

Parameter

Description

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.

Class Methods#

pressed()#

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

Parameters

Description

callback

The callback function to be called when the Limit Switch is pressed.

Returns: None.

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

Parameters

Description

callback

The callback function to be called when the Limit Switch is released.

Returns: None.

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