Εγκέφαλος#
Εισαγωγή#
In VEX EXP C++, the Brain is represented by the brain class. You create (or use the default project-provided) Brain object and then access Brain features through its member objects.
Παράγωγες Κλάσεις#
The brain class serves as a base class for the following derived classes:
Screen- This class provides access to the Brain’s built-in color touchscreen, allowing programs to display text, graphics, and receive touch input.Timer- This class provides high-resolution timing utilities for measuring elapsed time and controlling time-based behavior in programs.Battery- This class allows programs to monitor the Brain’s battery status, including voltage, current, capacity, and temperature.Button- This class allows programs to interact with the Brain’s buttons.ThreeWirePort(triport/ 3-Wire Port) - This class provides access to the Brain’s 3-Wire ports for connecting and controlling legacy sensors and devices such as limit switches, potentiometers, and LEDs.SDcard- This class enables reading from and writing to the Brain’s SD card for file storage, data logging, and loading external resources.
Κατασκευαστές κλάσεων#
brain();
Παράμετροι#
The brain constructor uses no parameters.
Σημειώσεις#
Only one
brainobject should be created in a project.
Παράδειγμα#
// Create the EXP Brain
brain Brain = brain();
Συναρτήσεις Μελών#
The brain class includes the following member functions:
playSound- Plays one of the Brain’s built-in sound effects.playNote- Plays a musical note for a specific duration.programStop- Stops the currently running project on the EXP Brain.timer- Returns the current value of the Brain’s internal timer in the specified units.resetTimer- Resets the Brain’s internal timer to zero and restarts timing.setTimer- Sets the Brain’s internal timer to a specified value and time unit.
Before calling any brain member functions, a brain instance must be created, as shown below:
// Create the EXP Brain
brain Brain = brain();
αναπαραγωγήΉχου#
Αναπαράγει έναν από τους ενσωματωμένους ήχους του εγκεφάλου.
Available Functionsvoid playSound(
soundtype sound,
uint32_t volume = 50 );
Παράμετροι |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Ο καθορισμένος ήχος που θα αναπαραχθεί από τον Εγκέφαλο. |
|
|
Προαιρετικό. Η ένταση ήχου στην οποία θα αναπαράγεται ο ήχος είναι ακέραια από 0% έως 100%. Η προεπιλογή είναι 50%. |
Όνομα ήχου |
Αναπαραγωγή ήχου |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
playNote#
Παίζει μια μουσική νότα από τον Εγκέφαλο.
Available Functions1 - Παίξε μια μουσική νότα.
void playNote( int32_t octave, int32_t note );
Parameters2 - Αναπαράγει μια νότα για καθορισμένη διάρκεια και ένταση.
void playNote( int32_t octave, int32_t note, int32_t duration, int32_t volume = 50 );
Παράμετροι |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The integer that represents the octave the note is played in:
|
|
|
The note to play:
|
|
|
Προαιρετικό. Η διάρκεια σε χιλιοστά του δευτερολέπτου για την αναπαραγωγή της νότας, έως και 500 χιλιοστά του δευτερολέπτου. Εάν δεν παρέχεται διάρκεια, η προεπιλεγμένη διάρκεια είναι 500 χιλιοστά του δευτερολέπτου. |
|
|
Προαιρετικό. Η ένταση ήχου στην οποία θα αναπαράγεται ο ήχος είναι ακέραια από 0% έως 100%. Η προεπιλογή είναι 50%. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
πρόγραμμαΔιακοπή#
Σταματά το έργο που εκτελείται αυτήν τη στιγμή στο EXP Brain.
Available Functionsvoid programStop();
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesΑυτή η συνάρτηση δεν επιστρέφει τιμή.
Examples// Stop the project when the Brain screen is pressed
while (true) {
if (Brain.Screen.pressing()) {
Brain.programStop();
}
wait(20, msec);
}
μετρών την ώραν#
Επιστρέφει την τρέχουσα τιμή του εσωτερικού χρονοδιακόπτη του εγκεφάλου στις καθορισμένες μονάδες.
Available Functionsdouble timer(
timeUnits units );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The unit of time to return:
|
Returns a double representing the elapsed time since the program started, in the specified units.
Ο χρονοδιακόπτης ξεκινά αυτόματα όταν ξεκινά το έργο.
The timer can be reset with the use of
resetTimer.
// Stop the project after 3 seconds
while (Brain.timer(seconds) < 3) {
wait(20, msec);
}
Brain.programStop();
Επαναφορά Χρονοδιακόπτη#
Μηδενίζει τον εσωτερικό χρονοδιακόπτη του εγκεφάλου. Στη συνέχεια, ο χρονοδιακόπτης αρχίζει αμέσως να μετράει ξανά από το μηδέν.
Available Functionsvoid resetTimer();
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Return ValuesΑυτή η συνάρτηση δεν επιστρέφει τιμή.
NotesΟ χρονοδιακόπτης αρχίζει να μετράει ξανά αμέσως μετά την επαναφορά του.
Calling
resetTimeraffects the value returned by subsequent calls totimer.
// Reset the timer and measure elapsed time
Brain.resetTimer();
while (Brain.timer(sec) < 5) {
wait(20, msec);
}
// 5 seconds have elapsed since reset
Brain.Screen.print("5 seconds passed");
ορισμός χρονοδιακόπτη#
Ρυθμίζει τον εσωτερικό χρονοδιακόπτη του εγκεφάλου σε μια συγκεκριμένη τιμή και μονάδα χρόνου.
Available Functionsvoid setTimer(
double value,
timeUnits units );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The time to set the timer to, based on the |
|
|
The unit used to interpret the
|
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
NotesΟ χρονοδιακόπτης συνεχίζει να μετράει προς τα εμπρός μετά τη ρύθμισή του.
Calling
setTimerimmediately changes the value returned bytimer.
// Set the timer to start at 10 seconds
Brain.setTimer(10, sec);
// Wait until the timer is at 3 seconds
while (Brain.timer(sec) < 3) {
wait(20, msec);
}
// 5 seconds have elapsed since setTimer was called
Brain.Screen.print("5 seconds passed");