脑#
介绍#
在 VEX V5 C++ 中,大脑由 brain 表示。您可以创建(或使用项目提供的默认)Brain 对象,然后通过其成员对象访问大脑功能。
派生类#
brain 类作为以下派生类的基类:
类构造函数#
brain();
参数#
brain 构造函数不使用任何参数。
笔记#
一个项目中只能创建一个
brain对象。
例子#
// Create the V5 Brain
brain Brain = brain();
成员功能#
brain 类包含以下成员函数:
programStop- 停止 V5 Brain 上当前正在运行的项目。timer- 返回大脑内部计时器的当前值,单位为指定单位。resetTimer- 将大脑的内部计时器重置为零并重新开始计时。setTimer- 将大脑的内部计时器设置为指定的值和时间单位。
在调用任何 brain 成员函数之前,必须先创建一个 brain 实例,如下所示:
// Create the V5 Brain
brain Brain = brain();
程序停止#
停止 V5 大脑上当前正在运行的项目。
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:
|
返回一个 double 表示自程序启动以来经过的时间,单位为指定值。
项目开始时,计时器会自动启动。
可以使用
resetTimer重置计时器。
// Stop the project after 3 seconds
while (Brain.timer(seconds) < 3) {
wait(20, msec);
}
Brain.programStop();
重置计时器#
将大脑内部计时器重置为零,之后,计时器立即从零开始重新计数。
Available Functionsvoid resetTimer();
此函数不接受任何参数。
Return Values此函数不返回值。
Notes计时器重置后会立即重新开始计时。
调用
resetTimer会影响后续对timer的调用返回的值。
// 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 unit used to interpret the
|
此函数不返回值。
Notes计时器设定好后会继续向前计时。
调用
setTimer立即改变timer返回的值。
// 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");