腦#
介紹#
在 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");