Κουμπί#
Εισαγωγή#
The button class is derived from the brain base class and provides access to the IQ (1st gen) Brain’s buttons, allowing your robot to monitor presses to the brain’s buttons.
Πρόσβαση#
The brain class provides twelve button objects. Each object is an instance of the button class and can be accessed through a brain instance.
Αντικείμενο |
Παράδειγμα Χρήσης |
Περιγραφή |
|---|---|---|
|
|
Κουμπί ελέγχου |
|
|
Αριστερό κουμπί |
|
|
Δεξί κουμπί |
Σημειώσεις#
The
buttonobject is provided by the brain. It is not constructed directly.
Συναρτήσεις Μελών#
The Button class includes the following member functions:
pressed— Registers a function to be called when the specified button is pressed.released— Registers a function to be called when the specified button is released.pressing— Returns whether the specified button is being pressed.
Before calling any button member functions, a brain instance must be created, as shown below:
// Create a brain instance
brain();
pressed#
Καταγράφει μια συνάρτηση επανάκλησης που εκτελείται όταν πατηθεί ένα συγκεκριμένο κουμπί του εγκεφάλου.
Available Functionsvoid pressed(
void (* callback)(void) ) const;
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Μια συνάρτηση που καλείται όταν πατηθεί το καθορισμένο κουμπί. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
ExamplesΑυτή η συνάρτηση μπορεί να κληθεί σε οποιοδήποτε αντικείμενο κουμπιού εγκεφάλου, για παράδειγμα:
Brain.buttonCheckBrain.buttonLeftBrain.buttonRight
Define the callback function (outside of
int main())// Drive forward when check is pressed void driveForward() { Drivetrain.driveFor(forward, 100, mm); }Register the callback inside
int main()int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Call driveForward when the check button is pressed Brain.buttonCheck.pressed(driveForward); }
released#
Καταγράφει μια συνάρτηση επανάκλησης που εκτελείται όταν απελευθερώνεται ένα συγκεκριμένο κουμπί του εγκεφάλου.
Available Functionsvoid released(
void (* callback)(void) ) const;
Παράμετροι#
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Μια συνάρτηση που καλείται όταν απελευθερώνεται το καθορισμένο κουμπί. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
ExamplesΑυτή η συνάρτηση μπορεί να κληθεί σε οποιοδήποτε αντικείμενο κουμπιού εγκεφάλου, για παράδειγμα:
Brain.buttonCheckBrain.buttonLeftBrain.buttonRight
Define the callback function (outside of
int main())// Drive backward when the left button is released void backUp() { Drivetrain.driveFor(reverse, 100, mm); }Register the callback inside
int main()int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Call backUp when the left button is released Brain.buttonLeft.released(backUp); }
pressing#
Επιστρέφει εάν πατιέται αυτήν τη στιγμή ένα συγκεκριμένο κουμπί του εγκεφάλου.
Available Functionsbool pressing() const;
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesΕπιστρέφει μια λογική τιμή που υποδεικνύει εάν πατιέται το καθορισμένο κουμπί:
true— The button is being pressed.false— The button is not being pressed.
Αυτή η συνάρτηση μπορεί να κληθεί σε οποιοδήποτε αντικείμενο κουμπιού εγκεφάλου, για παράδειγμα:
Brain.buttonCheckBrain.buttonLeftBrain.buttonRight
// Turn right while right is pressed
while (true) {
if (Brain.buttonRight.pressing()) {
Drivetrain.turn(right);
} else {
Drivetrain.stop();
}
wait(5, msec);
}