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
screenobject 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 Functions1 — Prints formatted text using string literals or read-only C-style strings.
void print( const char* format, ... );
Parameters2 — Prints formatted text using modifiable character arrays.
void print( char* format, ... );
Parameter |
Type |
Description |
|---|---|---|
|
|
A format string provided as a string literal or read-only C-style string (for example, |
|
|
A format string provided as a modifiable character array. |
|
One or more additional values that are inserted into the format string, separated by commas. |
This function does not return a value.
NotesOutput begins at the current cursor position on the screen.
When using a format string, the number and types of values passed must match the format specifiers in the string.
// 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 Functionsvoid setCursor(
int32_t row,
int32_t col );
Parameter |
Type |
Description |
|---|---|---|
|
|
The row number where the cursor will be placed. |
|
|
The column number where the cursor will be placed. |
This function does not return a value.
NotesAffects where subsequent text output begins when using print.
Calling
setCursoraffects the position of subsequent text output only.
// 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 Functionsvoid newLine();
This function does not accept any parameters.
Return ValuesThis function does not return a value.
NotesIf the cursor is in the middle of a sentence,
newLinewill 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.
// 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 Functionsvoid clearScreen();
This function does not accept any parameters.
Return ValuesThis 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 Functions1 — Clears the specified row on the screen.
void clearLine( int line );
Parameters2 — Clears the current row on the screen.
void clearLine();
Parameter |
Type |
Description |
|---|---|---|
|
|
The line to clear from 1 to 3. If not specified, the current line will be cleared. |
This function does not return a value.
NotesClearing a line does not change the current cursor position.
The cursor position and row numbering are set using setCursor.
// 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 Functionsint32_t row();
This function does not accept any parameters.
Return ValuesReturns an int32_t representing the current cursor row position.
Row numbering starts at 1.
NotesThe returned value indicates where the next printed output will appear.
The row value changes when text is printed or when setCursor is called.
// 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 Functionsint32_t column();
This function does not accept any parameters.
Return ValuesReturns an int32_t representing the current cursor column position.
Column numbering starts at 1.
NotesThe returned value indicates where the next printed output will appear.
The column value changes when text is printed or when setCursor is called.
// Display the cursor's current column
Controller.Screen.setCursor(3, 2);
Controller.Screen.print(Controller.Screen.column());