Screen#

Introduction#

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.

The controller screen has 3 rows and 19 columns for printing.

Access#

The screen class can be accessed by:

Controller.Screen

Notes#

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

Example#

/* 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!");

Member Functions#

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();

print#

Displays text, numbers, or Boolean values on the V5 Controller screen.

Available Functions

1 Prints formatted text using string literals or read-only C-style strings.

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

2 Prints formatted text using modifiable character arrays.

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

Parameters

Parameter

Type

Description

format

const char*

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

format

char*

A format string provided as a modifiable character array.

One or more additional values that are inserted into the format string, separated by commas.

Return Values

This function does not return a value.

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

setCursor#

Sets the cursor position on the V5 Controller screen to the specified row and column.

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

Parameters

Parameter

Type

Description

row

int32_t

The row number where the cursor will be placed.

col

int32_t

The column number where the cursor will be placed.

Return Values

This function does not return a value.

Notes
  • Affects where subsequent text output begins when using 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");

newLine#

Moves the cursor to the beginning of the next row on the controller screen.

Available Functions
void newLine();

Parameters

This function does not accept any parameters.

Return Values

This function does not return a value.

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.

  • The cursor position and row numbering are set using setCursor.

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

clearScreen#

Erases all text from the controller’s screen.

Available Functions
void clearScreen();

Parameters

This function does not accept any parameters.

Return Values

This function does not return a value.

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

clearLine#

Clears text from a row on the V5 Controller screen.

Available Functions

1 Clears the specified row on the screen.

void clearLine(
    int line );

2 Clears the current row on the screen.

void clearLine();

Parameters

Parameter

Type

Description

line

int

The line to clear from 1 to 3. If not specified, the current line will be cleared.

Return Values

This function does not return a value.

Notes
  • Clearing a line does not change the current cursor position.

  • The cursor position and row numbering are set using 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);

row#

Returns the current cursor row position on the V5 Controller screen.

Available Functions
int32_t row();

Parameters

This function does not accept any parameters.

Return Values

Returns an int32_t representing the current cursor row position.

Row numbering starts at 1.

Notes
  • The returned value indicates where the next printed output will appear.

  • The row value changes when text is printed or when setCursor is called.

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

column#

Returns the current cursor column position on the V5 Controller screen.

Available Functions
int32_t column();

Parameters

This function does not accept any parameters.

Return Values

Returns an int32_t representing the current cursor column position.

Column numbering starts at 1.

Notes
  • The returned value indicates where the next printed output will appear.

  • The column value changes when text is printed or when setCursor is called.

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