Διακόπτης ορίου#

Εισαγωγή#

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

Ο διακόπτης ορίου VEX V5.

Κατασκευαστής κλάσης#

limit(
  triport::port &port);

Καταστροφέας κλάσης#

Destroys the limit object and releases associated resources.

virtual ~limit();

Παράμετροι#

Παράμετρος

Τύπος

Περιγραφή

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

Παράδειγμα#

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

Συναρτήσεις Μελών#

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#

Επιστρέφει εάν ο διακόπτης ορίου είναι πατημένος τη δεδομένη στιγμή. Αυτό μπορεί να χρησιμοποιηθεί για να ελεγχθεί εάν το ρομπότ προσκρούει σε άλλα αντικείμενα.

Available Functions
int32_t pressing();

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#

Καταγράφει μια συνάρτηση που θα κληθεί όταν πατηθεί ο διακόπτης ορίου.

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

Parameters

Παράμετρος

Τύπος

Περιγραφή

callback

void (*)(void)

Ένας δείκτης σε μια συνάρτηση που θα καλείται όταν πατηθεί ο διακόπτης ορίου.

Return Values

Αυτή η συνάρτηση δεν επιστρέφει τιμή.

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#

Καταχωρεί μια συνάρτηση που θα κληθεί όταν απελευθερωθεί ο διακόπτης ορίου.

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

Parameters

Παράμετρος

Τύπος

Περιγραφή

callback

void (*)(void)

Ένας δείκτης σε μια συνάρτηση που θα κληθεί όταν απελευθερωθεί ο διακόπτης ορίου.

Return Values

Αυτή η συνάρτηση δεν επιστρέφει τιμή.

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);
}