脑#
介绍#
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%。 |
声音名称 |
播放声音 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
此函数不返回值。
播放音符#
从大脑中发出一个音符。
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");