屏幕#

介绍#

The screen class is derived from the controller base class, which controls the V5 controller’s touchscreen, allowing your robot to show text and numbers.

控制器屏幕有 3 行 19 列用于打印。

使用权#

The screen class can be accessed by:

Controller.Screen

笔记#

  • The screen object is provided by the controller. It is not constructed directly.

例子#

/* This constructor is required when using VS Code.
A controller is generated automatically at the start of
VEXcode projects. */

// Create the V5 Controller
controller Controller1 = controller(primary);

// Print text to the Controller screen
Controller.Screen.print("Hello!");

成员功能#

The screen class includes the following member functions:

  • print — Prints formatted text, numbers, or Boolean values to the controller’s screen.

  • setCursor — Sets the text cursor to a specified row and column.

  • newLine — Clears the remainder of the current line and moves the cursor to the next line.

  • clearScreen — Clears the the entire screen.

  • clearLine — Clears the remainder of the current line or clears a specified line.

  • row — Returns the current cursor row.

  • column — Returns the current cursor column.

Before calling any screen member functions, a controller instance must be created, as shown below:

// Create a V5 controller instance
controller Controller = controller();

打印#

在 V5 控制器屏幕上显示文本、数字或布尔值。

Available Functions

1 使用字符串字面量或只读 C 风格字符串打印格式化文本。

void print(
    const char* format,
    ... );

2 使用可修改的字符数组打印格式化文本。

void print(
    char* format,
    ... );

Parameters

范围

类型

描述

format

const char*

A format string provided as a string literal or read-only C-style string (for example, “Score: %d”).

format

char*

以可修改字符数组形式提供的格式字符串。

插入到格式字符串中的一个或多个附加值,以逗号分隔。

Return Values

此函数不返回值。

Notes Examples
// Display a message at the starting cursor
Controller.Screen.print("Hello, Robot!");

设置光标#

将 V5 控制器屏幕上的光标位置设置为指定的行和列。

Available Functions
void setCursor(
  int32_t row, 
  int32_t col );

Parameters

范围

类型

描述

row

int32_t

光标将放置的行号。

col

int32_t

光标将放置的列号。

Return Values

此函数不返回值。

Notes
  • 影响使用 print 时后续文本输出的起始位置。

  • Calling setCursor affects the position of subsequent text output only.

Examples
// Display text starting at Row 2 Column 3
Controller.Screen.setCursor(2, 3);
Controller.Screen.print("Row 2, Column 3");

换行符#

将光标移动到控制器屏幕上下一行的开头。

Available Functions
void newLine();

Parameters

此函数不接受任何参数。

Return Values

此函数不返回值。

Notes
  • If the cursor is in the middle of a sentence, newLine will clear the rest of the row after the cursor before moving to the next row.

  • After calling newLine, the cursor is positioned at the first column of the next line.

  • 使用 setCursor 设置光标位置和行号。

Examples
// Display two lines of text
Controller.Screen.print("Line 1");
Controller.Screen.newLine();
Controller.Screen.print("Line 2");

清屏#

清除控制器屏幕上的所有文字。

Available Functions
void clearScreen();

Parameters

此函数不接受任何参数。

Return Values

此函数不返回值。

Examples
// Clear screen after 2 seconds
Controller.Screen.print("VEXcode");
wait(2, seconds);
Controller.Screen.clearScreen();

清晰线#

清除 V5 控制器屏幕上某一行的文本。

Available Functions

1 清除屏幕上指定的行。

void clearLine(
    int line );

2 清除屏幕上的当前行。

void clearLine();

Parameters

范围

类型

描述

line

int

要清除的行号为 1 到 3。如果未指定,则清除当前行。

Return Values

此函数不返回值。

Notes
  • 清除一行不会改变当前光标位置。

  • 使用 setCursor 设置光标位置和行号。

Examples
// 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);

#

返回 V5 控制器屏幕上当前光标所在的行位置。

Available Functions
int32_t row();

Parameters

此函数不接受任何参数。

Return Values

Returns an int32_t representing the current cursor row position.

行号从1开始。

Notes
  • 返回值指示下一个打印输出将显示在哪里。

  • 当打印文本或调用 setCursor 时,行值会发生变化。

Examples
// Display the cursor's current row
Controller.Screen.setCursor(3, 2);
Controller.Screen.print(Controller.Screen.row());

柱子#

返回 V5 控制器屏幕上当前光标所在的列位置。

Available Functions
int32_t column();

Parameters

此函数不接受任何参数。

Return Values

Returns an int32_t representing the current cursor column position.

列编号从 1 开始。

Notes
  • 返回值指示下一个打印输出将显示在哪里。

  • 当打印文本或调用 setCursor 时,列值会发生变化。

Examples
// Display the cursor's current column
Controller.Screen.setCursor(3, 2);
Controller.Screen.print(Controller.Screen.column());