Screen#
Introduction#
The screen class is derived from the brain base class, which controls the V5 Brain’s touchscreen, allowing your robot to show text, numbers, and graphics, and respond to touch input.
By default, the font for printing to the Brain is monospaced small which has 12 rows and 48 columns.
For drawing, the Brain’s resolution is 479 x 239 pixels.

Access#
The screen class can be accessed by:
Brain.Screen
Notes#
The
screenobject is provided by the Brain. It is not constructed directly.Projects use a single global
Brainobject, so screen functions are called usingBrain.Screen.
Example#
/* This constructor is required when using VS Code.
A Brain is generated automatically at the start of
VEXcode projects. */
// Create the V5 Brain
brain Brain = brain();
// Print text to the Brain screen
Brain.Screen.print("Hello!");
Member Functions#
The screen class includes the following member functions:
print— Prints formatted text, numbers, or Boolean values to the Brain 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.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.getStringHeight— Returns the height of a string in pixels using the current font.getStringWidth— Returns the width of a string in pixels using the current font.printAt— Prints formatted text at an x, y pixel location (optionally opaque).clearScreen— Clears the entire screen (optionally to a specified color).setFont— Sets the font used for printing on the screen.setPenWidth— Sets the width of lines and shape outlines.setPenColor— Sets the color used for drawing and printed text.setFillColor— Sets the fill color used for shapes and the background of printed text.setOrigin— Sets the origin used for screen coordinates.setClipRegion— Restricts screen output to a rectangular region.drawPixel— Draws a single pixel at an x, y location.drawLine— Draws a line between two points.drawRectangle— Draws a rectangle at an x, y location with a specified size.drawCircle— Draws a circle at an x, y location with a specified radius.drawImageFromFile— Draws an image from an SD card file onto the screen.render— Enables double buffering or renders the back buffer to the screen.pressing— Returns a Boolean indicating whether the screen is currently being pressed.xPosition— Returns the x-coordinate of the most recent screen press.yPosition— Returns the y-coordinate of the most recent screen press.pressed— Registers a callback function to run when the screen is pressed.released— Registers a callback function to run when the screen is released after being pressed.
Before calling any screen member functions, a brain instance must be created, as shown below:
// Create the V5 Brain
brain Brain = brain();
print#
Displays text, numbers, or Boolean values on the V5 Brain screen.
Available Functions >| 1 |
|
|
| 2 |
|
|
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.
Printed text uses the current screen font.
Printed text uses the current pen color.
Text printed with
printis always printed with a background, and the background color is determined by the current fill color.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
Brain.Screen.print("Hello, Robot!");

setCursor#
Sets the cursor position on the V5 Brain 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.Rows and columns are based on the currently set screen font.
The default font (
mono20) uses 12 rows and 48 columns.Calling
setCursoraffects the position of subsequent text output only.
// Display text starting at Row 3 Column 12
Brain.Screen.setCursor(3, 12);
Brain.Screen.print("Row 3, Column 12");

newLine#
Moves the cursor to the beginning of the next row on the Brain 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
Brain.Screen.print("Line 1");
Brain.Screen.newLine();
Brain.Screen.print("Line 2");

clearLine#
Clears text from a row on the V5 Brain screen.
Available Functions| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
Parameter |
Type |
Description |
|---|---|---|
|
|
The row number to clear. Row numbering starts at |
|
|
Clears the row using a
|
|
|
Clears the row using a hexadecimal color value (for example, |
|
|
Clears the row using an integer hue value in the range |
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.The
hueparameter value is based on a circular color wheel, as shown below, where values represent degrees around the wheel (for example, red near 0°, green near 120°, and blue near 240°).

// Display text on two rows
Brain.Screen.print("This text stays");
Brain.Screen.newLine();
Brain.Screen.print("This disappears");
// Wait 3 seconds before clearing row 2
wait(3, seconds);
Brain.Screen.clearLine(2);
row#
Returns the current cursor row position on the V5 Brain 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 cursor position is based on the current screen font.
The returned value indicates where the next printed output will appear.
The row value changes when text is printed or when
setCursoris called.
// Display the cursor's current row
Brain.Screen.setCursor(3, 12);
Brain.Screen.print(Brain.Screen.row());

column#
Returns the current cursor column position on the V5 Brain 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 cursor position is based on the current screen font.
The returned value indicates where the next printed output will appear.
The column value changes when text is printed or when
setCursoris called.
// Display the cursor's current column
Brain.Screen.setCursor(5, 15);
Brain.Screen.print(Brain.Screen.column());

getStringHeight#
Returns the height, in pixels, of a string when rendered on the V5 Brain screen.
Available Functionsint32_t getStringHeight(
const char* cstr );
Parameter |
Type |
Description |
|---|---|---|
|
|
The text to be measured, provided as a C-style string (for example, |
Returns an int32_t representing the height of the string in pixels when rendered on the Brain screen.
The returned height depends on the currently selected screen font.
This function measures the string without drawing it to the screen.
The returned height reflects how the string would appear when printed.
getStringWidth#
Returns the width, in pixels, of a string when rendered on the V5 Brain screen.
Available Functionsint32_t getStringWidth(
const char* cstr );
Parameter |
Type |
Description |
|---|---|---|
|
|
The text to be measured, provided as a C-style string (for example, |
Returns an int32_t representing the width of the string in pixels when rendered on the Brain screen.
The returned width depends on the currently selected screen font.
This function measures the string without drawing it to the screen.
The returned width reflects how the string would appear when printed.
printAt#
Prints text, numbers, or Boolean values at a specific coordinate on the V5 Brain screen.
Available Functions<tr style="border-bottom: 1px solid #ccc;">
<td>1</td>
<td>
<pre><code class="language-cpp">void printAt(
int32_t x, int32_t y, const char* format, … );
|
||
| 2 |
|
|
Parameter |
Type |
Description |
|---|---|---|
|
|
The x-position to print at, referenced to the screen origin. |
|
|
The y-position to print at, referenced to the screen origin. |
|
|
Controls whether the printed text is drawn opaquely or transparently:
|
|
|
A format string that controls what is printed on the screen (for example, |
|
One or more additional values that are inserted into the format string, separated by commas. |
This function does not return a value.
NotesThe
xandycoordinates are relative to the current screen origin, which can be changed usingsetOrigin.Printed text uses the current screen font.
Printed text uses the
current pen color.When using a format string, the number and types of values passed must match the format specifiers in the string.
// Print the number 1 at pixel (100, 40)
Brain.Screen.printAt(220, 120, "Center");

clearScreen#
Erases all drawings and text from the Brain’s screen.
Available Functions| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
Parameter |
Type |
Description |
|---|---|---|
|
|
Clears the screen using a
|
|
|
Clears the screen using a hexadecimal color value represented as a string (for example, |
|
|
Clears the screen using an integer hue value in the range |
This function does not return a value.
NotesThe
hueparameter value is based on a circular color wheel, as shown below, where values represent degrees around the wheel (for example, red near 0°, green near 120°, and blue near 240°).

// Clear screen after 2 seconds
Brain.Screen.print("VEXcode");
wait(2, seconds);
Brain.Screen.clearScreen();
// Clear screen to blue after 2 seconds
Brain.Screen.print("VEXcode");
wait(2, seconds);
Brain.Screen.clearScreen(blue);

setFont#
Sets the font used for text displayed on the V5 Brain screen.
This controls the font applied to subsequent text output when using screen text functions such as print.
void setFont(
fontType font );
Parameter |
Type |
Description |
|---|---|---|
|
|
Sets the font to one of the following:
|
|
|
|
|---|---|---|
|
|
|
|
|
|
|
|
This function does not return a value.
Examples// Print larger text
Brain.Screen.setFont(mono40);
Brain.Screen.print("VEX");

// Print in Chinese
Brain.Screen.setFont(fontType::cjk16);
Brain.Screen.print("VEX机器人");

setPenWidth#
Sets the pen width used for drawing lines and shapes.
Available Functionsvoid setPenWidth(
uint32_t width );
Parameter |
Type |
Description |
|---|---|---|
|
|
The pen width in pixels as a range from 0 to 32. |
This function does not return a value.
NotesThe pen width applies to drawing functions such as
drawLine,drawRectangle, anddrawCircle.
// Draw a rectangle with a pen width of 10
Brain.Screen.setPenWidth(10);
Brain.Screen.drawRectangle(50, 50, 130, 60);

setPenColor#
Sets the pen color used for drawing lines, shapes, and text.
Available Functions| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
Parameter |
Type |
Description |
|---|---|---|
|
|
Sets the pen color using a
|
|
|
Sets the pen color using a hexadecimal color value represented as a string (for example, |
|
|
Sets the pen color using an integer hue value in the range |
This function does not return a value.
NotesThe default pen color at the start of a project is
white.The pen color is used for outlines of shapes (such as with
drawCircleordrawRectangle), text and numeric output (withprintandprintAt), and individual pixels drawn withdrawPixel.The
hueparameter value is based on a circular color wheel, as shown below, where values represent degrees around the wheel (for example, red near 0°, green near 120°, and blue near 240°).

```cpp
// Draw a rectangle with orange borders
Brain.Screen.setPenColor(orange);
Brain.Screen.drawRectangle(50, 50, 130, 60);

setFillColor#
Sets the fill color used when shapes are drawn.
Available Functions| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
Parameter |
Type |
Description |
|---|---|---|
|
|
Sets the fill color using a
|
|
|
Sets the fill color using a hexadecimal color value represented as a string (for example, |
|
|
Sets the fill color using an integer hue value in the range |
This function does not return a value.
NotesThe default fill color at the start of a project is
black.The fill color is used for interior of shapes (such as with
drawCircleordrawRectangle).The fill color is used as the background color for printed text (such as with
printandprintAt).If
transparentis used with printed text, the background will beblack.
The
hueparameter value is based on a circular color wheel, as shown below, where values represent degrees around the wheel (for example, red near 0°, green near 120°, and blue near 240°).

// Draw a rectangle filled with purple
Brain.Screen.setFillColor(purple);
Brain.Screen.drawRectangle(50, 100, 130, 60);

setOrigin#
Sets the origin used for drawing graphics on the Brain’s screen.
Available Functionsvoid setOrigin(
int32_t x,
int32_t y );
Parameter |
Type |
Description |
|---|---|---|
|
|
The origin’s x-position relative to top left corner of the Brain’s screen from 0 to 480. |
|
|
The origin’s y-position relative to top left corner of the Brain’s screen from 0 to 480. |
This function does not return a value.
NotesThe default origin is the top-left corner of the screen at coordinate (0, 0).
The origin applies to coordinate functions such as
drawLine,drawRectangle,drawCircle, andprintAt.The origin remains in effect until changed again or the project is reset.
setClipRegion#
Defines a rectangular area on the screen where all drawings and text will be confined. Any content outside this region will not be displayed.
Available Functionsvoid setClipRegion(
int x,
int y,
int width,
int height );
Parameter |
Type |
Description |
|---|---|---|
|
|
The x-coordinate of the top-left corner of the clip region, given as an integer from 0 to 480. |
|
|
The y-coordinate of the top-left corner of the clip region, given as an integer from 0 to 240. |
|
|
The width of the clip region in pixels, given as an integer from 0 to 480. |
|
|
The height of the clip region in pixels, given as an integer from 0 to 240. |
This function does not return a value.
NotesDrawing functions are still executed even if they fall outside the clip region, but only the portion inside the region is visible.
The
xandycoordinates are relative to the current screen origin, which can be changed usingsetOrigin.The clip region applies only to the current thread.
Setting a new clip region replaces any previously set clip region for the current thread.
// Restrict text and drawings to a specific region
Brain.Screen.setClipRegion(0, 0, 120, 120);
Brain.Screen.drawRectangle(60, 60, 100, 100, red);
Brain.Screen.printAt(60, 60, "Cut off!");

drawPixel#
Draws a single pixel on the V5 Brain screen at the specified x and y pixel location.
Available Functionsvoid drawPixel(
int x,
int y );
Parameter |
Type |
Description |
|---|---|---|
|
|
The x-coordinate where the pixel will be drawn, given as an integer from 0 to 480. |
|
|
The y-coordinate where the pixel will be drawn, given as an integer from 0 to 240. |
This function does not return a value.
NotesPixels are drawn using the current pen color set with
setPenColor.The
xandycoordinates are relative to the current screen origin, which can be set usingsetOrigin.If the specified pixel location is outside the screen bounds, the pixel is not drawn.
// Draw the pixels marking the corners of a square
Brain.Screen.drawPixel(250, 100);
Brain.Screen.drawPixel(275, 100);
Brain.Screen.drawPixel(250, 125);
Brain.Screen.drawPixel(275, 125);
![]()
drawLine#
Draws a straight line connecting two points on the V5 Brain screen.
Available Functionsvoid drawLine(
int x1,
int y1,
int x2,
int y2 );
Parameter |
Type |
Description |
|---|---|---|
|
|
The starting x-coordinate of the line, given as an integer from 0 to 480. |
|
|
The starting y-coordinate of the line, given as an integer from 0 to 240. |
|
|
The ending x-coordinate of the line, given as an integer from 0 to 480. |
|
|
The ending y-coordinate of the line, given as an integer from 0 to 240. |
This function does not return a value.
NotesLines are drawn using the current pen color set with
setPenColor.The width of the line is determined by the current pen width set with
setPenWidth.The
xandycoordinates are relative to the current screen origin, which can be set usingsetOrigin.If any portion of the line lies outside the screen bounds, only the visible portion is drawn.
// Draw a line from the top left to bottom right of the screen
Brain.Screen.drawLine(0, 0, 479, 239);

drawRectangle#
Draws a rectangle on the V5 Brain screen at the specified position and size.
Available Functions| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
Parameter |
Type |
Description |
|---|---|---|
|
|
The x-coordinate of the top-left corner of the rectangle, given as an integer from 0 to 480. |
|
|
The y-coordinate of the top-left corner of the rectangle, given as an integer from 0 to 240. |
|
|
The width of the rectangle, given as an integer from 0 to 480. |
|
|
The height of the rectangle, given as an integer from 0 to 240. |
|
|
Fills the rectangle using a
|
|
|
Fills the rectangle using a hexadecimal color value (for example, |
|
|
Fills the rectangle using a hue value in the range |
This function does not return a value.
NotesThe rectangle outline is drawn using the current pen color set with
setPenColor.The outline thickness is determined by the current pen width set with
setPenWidth.When no
colorparameter is provided, the rectangle interior is filled using the current fill color set withsetFillColor.The
xandycoordinates are relative to the current screen origin, which can be changed usingsetOrigin.If any portion of the rectangle lies outside the screen bounds, only the visible portion is drawn.
The
hueparameter value is based on a circular color wheel, as shown below, where values represent degrees around the wheel (for example, red near 0°, green near 120°, and blue near 240°).

// Draw a rectangle on the screen
Brain.Screen.drawRectangle(50, 50, 130, 60);

drawCircle#
Draws a circle on the V5 Brain screen at the specified position and radius.
Available Functions| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
Parameter |
Type |
Description |
|---|---|---|
|
|
The x-coordinate of the center of the circle, given as an integer from 0 to 480. |
|
|
The y-coordinate of the center of the circle, given as an integer from 0 to 240. |
|
|
The radius of the circle, given as an integer from 0 to 240 pixels. |
|
|
Fills the circle using a
|
|
|
Fills the circle using a hexadecimal color value (for example, |
|
|
Fills the circle using a hue value in the range |
This function does not return a value.
NotesThe circle outline is drawn using the current pen color set with
setPenColor.The outline thickness is determined by the current pen width set with
setPenWidth.When no
colorparameter is provided, the circle interior is filled using the current fill color set withsetFillColor.The
xandycoordinates are relative to the current screen origin, which can be changed usingsetOrigin.The
hueparameter value is based on a circular color wheel, as shown below, where values represent degrees around the wheel (for example, red near 0°, green near 120°, and blue near 240°).

// Draw a circle on the screen
Brain.Screen.drawCircle(240, 120, 40);

drawImageFromFile#
Draws an image on the V5 Brain screen using an image file stored on the SD card.
Available Functionsbool drawImageFromFile(
const char* name,
int x,
int y );
Parameter |
Type |
Description |
|---|---|---|
|
|
The filename of the image on the SD card. The file must have a |
|
|
The x-coordinate, in pixels from 0 to 480, at which the left edge of the image will be drawn. |
|
|
The y-coordinate, in pixels from 0 to 240, at which the top edge of the image will be drawn. |
Returns a Boolean indicating whether the image was successfully drawn:
true— The image was successfully loaded and drawn on the screen.false— The image could not be drawn (for example, if the file does not exist or is invalid).
Supported image formats are
.bmpand.png.The image file size must not exceed
512 KB.8-bit RLE encoding is recommended to minimize file size.
The maximum supported image dimensions are the size of the Brain screen (approximately 479 x 239 pixels).
The
xandycoordinates are relative to the current screen origin, which can be changed usingsetOrigin.
// Draw a bmp file on the Brain's screen at coordinate 0, 0
Brain.Screen.drawImageFromFile("test_image.bmp", 0, 0);
render#
Enables double buffering for the Brain’s screen. Once called, any drawing functions (like text, shapes, or images) will no longer appear immediately for the rest of the project. Instead, updates will only be shown when render is used again. This allows for smoother and more controlled screen updates, but means nothing will be visible until render is used.
| 1 |
|
|
| 2 |
|
|
Parameter |
Type |
Description |
|---|---|---|
|
|
|
|
|
Optional.
|
Returns a Boolean indicating whether the saved drawings in the buffer were successfully rendered to the screen:
true— The drawings were successfully rendered on the screen.false— The drawings could not be rendered on the screen.
Notes
Calling
renderwill requirerenderto be used for the rest of the project.
Brain.Screen.render();
// Draw text to the back buffer
Brain.Screen.print("Render later...");
// Wait for a screen press to render drawings
while (!Brain.Screen.pressing()) {
wait(20, msec);
}
Brain.Screen.render();
pressing#
Returns a Boolean indicating whether the V5 Brain screen is currently being pressed.
Available Functionsbool pressing();
This function does not accept any parameters.
Return ValuesReturns a Boolean indicating the current pressed state of the screen:
true— The screen is currently being pressed.false— The screen is not being pressed.
Examples
// Change the screen's color after it's pressed
while (Brain.Screen.pressing() == false) {
wait(5, msec);
}
Brain.Screen.setFillColor(green);
Brain.Screen.drawRectangle(0, 0, 479, 239);
// Display different messages after the screen is pressed
while (!Brain.Screen.pressing()) {
wait(5, msec);
}
Brain.Screen.print("First message!");
Brain.Screen.newLine();
// Lift finger to press the screen again
while (Brain.Screen.pressing()) {
wait(5, msec);
}
while (Brain.Screen.pressing() == false) {
wait(5, msec);
}
Brain.Screen.print("Second message!");
Brain.Screen.newLine();
xPosition#
Returns the x-coordinate of the most recent press on the V5 Brain screen.
Available Functionsint32_t xPosition();
This function does not accept any parameters.
Return ValuesReturns an int32_t representing the x-coordinate, in pixels between 0 and 480, of the most recent screen press.
// Display a circle where the screen is pressed
while (Brain.Screen.pressing() == false) {
wait(5, msec);
}
Brain.Screen.drawCircle(Brain.Screen.xPosition(), Brain.Screen.yPosition(), 20, white);
yPosition#
Returns the y-coordinate of the most recent press on the V5 Brain screen.
Available Functionsint32_t yPosition();
This function does not accept any parameters.
Return ValuesReturns an int32_t representing the y-coordinate, in pixels between 0 and 240, of the most recent screen press.
// Display a circle where the screen is pressed
while (Brain.Screen.pressing() == false) {
wait(5, msec);
}
Brain.Screen.drawCircle(Brain.Screen.xPosition(), Brain.Screen.yPosition(), 20, white);
pressed#
Registers a function to be called when the V5 Brain screen is pressed.
Available Functions| 1 |
|
|
| 2 |
|
|
Parameter |
Type |
Description |
|---|---|---|
|
|
A function that is called when the screen is pressed. |
|
|
A function that is called when the screen is pressed and receives a user-defined argument. |
|
|
A user-defined value that is passed to the callback function when the screen is pressed. |
This function does not return a value.
NotesThe callback function is executed each time the Brain screen is pressed.
Only one callback function can be registered at a time; calling
pressedagain replaces the previous callback.The callback function must return
void.
// Tracks how many times the screen is pressed
void onScreenPressed(void* arg) {
int* count = (int*)arg;
(*count)++;
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Pressed %d times", *count);
}
int pressCount = 0;
// Register the callback and pass a value to update
Brain.Screen.pressed(onScreenPressed, &pressCount);
released#
Registers a function to be called when the V5 Brain screen is released after being pressed.
Available Functions| 1 |
|
|
| 2 |
|
|
Parameter |
Type |
Description |
|---|---|---|
|
|
A function that is called when the screen is released after being pressed. |
|
|
A function that is called when the screen is released after being pressed and receives a user-defined argument. |
|
|
A user-defined value that is passed to the callback function when the screen is released after being pressed. |
This function does not return a value.
NotesThe callback function is executed each time the Brain screen is released after being pressed.
Only one callback function can be registered at a time; calling
releasedagain replaces the previous callback.The callback function must return
void.
// Tracks how many times the screen is released
void onScreenReleased(void* arg) {
int* count = (int*)arg;
(*count)++;
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
Brain.Screen.print("Released %d times", *count);
}
int pressCount = 0;
// Register the callback and pass a value to update
Brain.Screen.released(onScreenReleased, &pressCount);










