Διακόπτης ορίου#
Εισαγωγή#
The limit class is used with the Limit Switch, a small digital sensor that detects physical contact with an object.

Κατασκευαστής κλάσης#
limit(
triport::port &port);
Καταστροφέας κλάσης#
Destroys the limit object and releases associated resources.
virtual ~limit();
Παράμετροι#
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The 3-Wire Port that the Limit Switch is connected to, written as |
Παράδειγμα#
// 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 Functionsint32_t pressing();
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesReturns 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 Functionsvoid pressed(
void (* callback)(void) );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Ένας δείκτης σε μια συνάρτηση που θα καλείται όταν πατηθεί ο διακόπτης ορίου. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
ExamplesDefine 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 Functionsvoid released(
void (* callback)(void) );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Ένας δείκτης σε μια συνάρτηση που θα κληθεί όταν απελευθερωθεί ο διακόπτης ορίου. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
ExamplesDefine 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); }