Διακόπτης προφυλακτήρα#
Εισαγωγή#
The bumper class is used to detect when the Bumper Switch is pressed and released.
Κατασκευαστής κλάσης#
bumper(
int32_t index );
Καταστροφέας κλάσης#
Destroys the bumper object and releases associated resources.
virtual ~bumper();
Παράμετροι#
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The Smart Port that the Bumper Switch is connected to, written as |
Παράδειγμα#
// Create a bumper instance in Port 1
bumper Bumper1 = bumper(PORT1);
Συναρτήσεις Μελών#
The bumper class includes the following member functions:
pressing— Returns if the Bumper Switch is being pressed.pressed— Registers a function to be called when the Bumper Switch is pressed.released— Registers a function to be called when the Bumper Switch is released.
Before calling any bumper member functions, a bumper instance must be created, as shown below:
/* This constructor is required when using VS Code.
Bumper Switch configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a bumper instance in Port 1
bumper Bumper1 = bumper(PORT1);
pressing#
Επιστρέφει εάν ο διακόπτης προφυλακτήρα είναι πατημένος τη δεδομένη στιγμή.
Available Functionsint32_t pressing();
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesReturns an int32_t indicating whether the Bumper Switch is being pressed.
1— The Bumper Switch is being pressed.0— The Bumper Switch is not being pressed.
pressed#
Καταγράφει μια λειτουργία που θα κληθεί όταν πατηθεί ο διακόπτης προφυλακτήρα.
Available Functionsvoid pressed( void (* callback)(void) );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Ένας δείκτης σε μια συνάρτηση που θα κληθεί όταν πατηθεί το κουμπί bumper. Η συνάρτηση δεν πρέπει να δέχεται παραμέτρους και να επιστρέφει void. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
ExamplesDefine the callback function (outside of
int main())// Display a message when bumper is pressed void BumperPressed() { Brain.Screen.print("Bumper 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 BumperPressed when the value of the Bumper Switch is pressed. Bumper1.pressed(BumperPressed); }
released#
Καταγράφει μια συνάρτηση που θα κληθεί όταν απελευθερωθεί ο διακόπτης προφυλακτήρα.
Available Functionsvoid released( void (* callback)(void) );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Ένας δείκτης σε μια συνάρτηση που θα κληθεί όταν απελευθερωθεί το bumper. Η συνάρτηση δεν πρέπει να δέχεται παραμέτρους και να επιστρέφει void. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
ExamplesDefine the callback function (outside of
int main())// Display a message when bumper is released void BumperReleased() { Brain.Screen.print("Bumper 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 BumperReleased when the value of the Bumper Switch is released. Bumper1.released(BumperReleased); }