屏幕#
介绍#
screen 类是 controller 类的派生类。它提供了在 V5 控制器屏幕上显示文本、数字和值的功能。
screen 对象是通过 controller 对象访问的,它不是直接构造的。
V5 控制器屏幕有 3 行 19 列,用于显示文本和数字。
使用权#
controller 类提供了 Screen 对象。它是 screen 类的一个实例。
目的 |
用法示例 |
描述 |
|---|---|---|
|
|
V5 控制器屏幕。 |
笔记#
在使用
screen成员函数之前,请创建一个controller对象。控制器屏幕有 3 行 19 列。
光标位置决定了下一个打印值出现的位置。
// Create a Controller object
controller Controller = controller();
成员功能#
screen 类包含以下成员函数:
操作——显示文本或清除控制器屏幕。
print— 在控制器屏幕上显示格式化的文本、数字或值。setCursor— 将光标移动到指定的行和列。newLine— 清除当前行的其余部分并将光标移动到下一行。clearScreen— 清除控制器屏幕。clearLine— 清除控制器屏幕上的一行。
Getter 方法 — 读取当前光标位置。
行动#
print#
print 在 V5 控制器屏幕上当前光标位置显示格式化的文本、数字或值。
可用功能
void print(
const char* format,
...
);
void print(
char* format,
...
);
范围 |
类型 |
描述 |
|---|---|---|
|
|
格式字符串以字符串字面量或只读 C 风格字符串的形式提供,例如 |
|
|
以可修改字符数组形式提供的格式字符串。 |
|
可选。在格式字符串中插入一个或多个附加值,以逗号分隔。 |
返回值
此函数不返回值。
笔记
输出从控制器屏幕上的当前光标位置开始。
使用格式字符串时,传递的值的数量和类型必须与字符串中的 格式说明符 匹配。
例子
// Display a message at the starting cursor position
Controller.Screen.print("Hello, Robot!");
// Display a formatted number
Controller.Screen.print("Score: %d", 25);
setCursor#
setCursor 将光标移动到 V5 控制器屏幕上的指定行和列。下一个打印值将显示在该位置。
可用功能
void setCursor(
int32_t row,
int32_t col
);
范围 |
类型 |
描述 |
|---|---|---|
|
|
光标将放置的行号,从 |
|
|
光标将放置的列号,从 |
返回值
此函数不返回值。
例子
// Display text starting at row 2, column 3
Controller.Screen.setCursor(2, 3);
Controller.Screen.print("Row 2, Column 3");
newLine#
newLine 清除当前行的其余部分,并将光标移动到 V5 控制器屏幕下一行的第 1 列。
可用功能
void newLine();
参数
此函数没有参数。
返回值
此函数不返回值。
例子
// Display two lines of text
Controller.Screen.print("Line 1");
Controller.Screen.newLine();
Controller.Screen.print("Line 2");
clearScreen#
clearScreen 清除 V5 控制器屏幕上的所有文本。
可用功能
void clearScreen();
参数
此函数没有参数。
返回值
此函数不返回值。
例子
// Clear the Controller screen after 2 seconds
Controller.Screen.print("VEXcode");
wait(2, seconds);
Controller.Screen.clearScreen();
clearLine#
clearLine 清除 V5 控制器屏幕上的一行。
可用功能
void clearLine(
int line
);
void clearLine();
范围 |
类型 |
描述 |
|---|---|---|
|
|
可选。要清除的行,从 |
返回值
此函数不返回值。
笔记
清除一行不会改变当前光标位置。
例子
// Display text on two rows
Controller.Screen.print("This text stays");
Controller.Screen.newLine();
Controller.Screen.print("This disappears");
// Wait 3 seconds before clearing row 2
wait(3, seconds);
Controller.Screen.clearLine(2);
获取器#
row#
row 返回 V5 控制器屏幕上的当前光标行。
可用功能
int32_t row();
参数
此函数没有参数。
返回值
返回一个 int32_t 表示当前光标所在行。行号从 1开始。
例子
// Display the cursor's current row
Controller.Screen.setCursor(3, 2);
Controller.Screen.print(Controller.Screen.row());
column#
column 返回 V5 控制器屏幕上的当前光标列。
可用功能
int32_t column();
参数
此函数没有参数。
返回值
返回一个 int32_t ,表示当前游标列。列编号从 1开始。
例子
// Display the cursor's current column
Controller.Screen.setCursor(3, 2);
Controller.Screen.print(Controller.Screen.column());