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.

A labeled grid diagram of the VEX Brain screen showing rows, columns, pixel dimensions, and coordinates, with red lines outlining the grid.

Access#

The screen class can be accessed by:

Brain.Screen

Notes#

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

  • Projects use a single global Brain object, so screen functions are called using Brain.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
void print(
    const char* format,
    ... );
  • Accepts string literals and read-only C-style strings
2
void print(
    char* format,
    ... );
  • Accepts modifiable character arrays
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
Brain.Screen.print("Hello, Robot!");

A screenshot of the V5 Brain showing "Hello Robot" printed on the screen.

setCursor#

Sets the cursor position on the V5 Brain 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.

  • Rows and columns are based on the currently set screen font.

  • The default font (mono20) uses 12 rows and 48 columns.

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

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

A screenshot of the V5 Brain showing "Row 3 Column 12" printed on the screen.

newLine#

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

A screenshot of the V5 Brain showing the text "Line 1" printed above "Line 2".

clearLine#

Clears text from a row on the V5 Brain screen.

Available Functions
1
void clearLine();
  • Clears the rest of the line from where the cursor is located
2
void clearLine(
    int number
);
  • Clears the specified row using the currently configured fill color
3
void clearLine(
    int number,
    const color& color
);
  • Clears the specified row using a predefined or custom color object
4
void clearLine(
    int number,
    const char* color
);
  • Clears the specified row using a hexadecimal color value
5
void clearLine(
    int number,
    int hue
);
  • Clears the specified row using a hue value
Parameters

Parameter

Type

Description

number

int

The row number to clear. Row numbering starts at 1.

color

const color&

Clears the row using a color object. Predefined colors include:

  • black
  • white
  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan
  • transparent
This can also use a custom color object.

color

const char*

Clears the row using a hexadecimal color value (for example, “#000000”).

hue

int

Clears the row using an integer hue value in the range 0359, representing degrees around a color wheel.

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.

  • The hue parameter 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°).

A color wheel showing the range of colors from 0 to 359, where red is 0, green is 120, and blue is 240.

Examples
// 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 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 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 setCursor is called.

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

A screenshot of the V5 Brain showing the text "3" on row 3.

column#

Returns the current cursor column position on the V5 Brain 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 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 setCursor is called.

Examples
// Display the cursor's current column
Brain.Screen.setCursor(5, 15);
Brain.Screen.print(Brain.Screen.column());

A screenshot of the V5 Brain showing the text "15" on column 15.

getStringHeight#

Returns the height, in pixels, of a string when rendered on the V5 Brain screen.

Available Functions
int32_t getStringHeight( 
    const char* cstr );

Parameters

Parameter

Type

Description

cstr

const char*

The text to be measured, provided as a C-style string (for example, “Hello”).

Return Values

Returns an int32_t representing the height of the string in pixels when rendered on the Brain screen.

Notes
  • 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 Functions
int32_t getStringWidth( 
    const char* cstr );

Parameters

Parameter

Type

Description

cstr

const char*

The text to be measured, provided as a C-style string (for example, “Hello”).

Return Values

Returns an int32_t representing the width of the string in pixels when rendered on the Brain screen.

Notes
  • 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, … );

  • Prints formatted output at a specific pixel location
2
void printAt(
int32_t x,
int32_t y,
bool bOpaque,
const char* format,
… );
  • Allows printed output to be opaque or transparent
Parameters

Parameter

Type

Description

x

int32_t

The x-position to print at, referenced to the screen origin.

y

int32_t

The y-position to print at, referenced to the screen origin.

bOpaque

bool

Controls whether the printed text is drawn opaquely or transparently:

  • true — The background of the printed text is filled using the current fill color set with setFillColor.
  • false — The text is drawn transparently and the background is not filled.

format

const char*

A format string that controls what is printed on the screen (for example, “Score: %d”).

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
// Print the number 1 at pixel (100, 40)
Brain.Screen.printAt(220, 120, "Center");

A screenshot of the V5 Brain showing the text "center" at the center of the screen.

clearScreen#

Erases all drawings and text from the Brain’s screen.

Available Functions
1
void clearScreen();
  • Clears the screen to black
2
void clearScreen(
  const color& color );
  • Clears the screen using a predefined or custom color object
3
void clearScreen(
  const char *color );
  • Clears the screen using a hexadecimal color value
4
void clearScreen(
  int hue );
  • Clears the screen using a hue value
Parameters

Parameter

Type

Description

color

const color&

Clears the screen using a color object. Predefined colors include:

  • black
  • white
  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan
  • transparent
This can also use a custom color object.

color

const char

Clears the screen using a hexadecimal color value represented as a string (for example, “#000000”).

hue

int

Clears the screen using an integer hue value in the range 0359, representing degrees around a color wheel.

Return Values

This function does not return a value.

Notes
  • The hue parameter 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°).

A color wheel showing the range of colors from 0 to 359, where red is 0, green is 120, and blue is 240.

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

A screenshot of the V5 Brain with a blue screen.

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.

Available Functions
void setFont(
  fontType font );

Parameters

Parameter

Type

Description

font

fontType

Sets the font to one of the following:

  • mono12
  • mono15
  • mono20
  • mono30
  • mono40
  • mono60
  • prop20
  • prop30
  • prop40
  • prop60
  • fontType::cjk16 — Can print Chinese, Japanese, and Korean characters.
    • Simplified Chinese — Can be seen up to column 28.
    • Traditional Chinese — Can be seen up to column 28.
    • Japanese (Kanji) — Can be seen up to column 28.
    • Korean (Hangul) — Can be seen up to column 30.
These options are shown below.

The robot screen printed numbers and letters with MONO 12 font. It shows A-Z. On the bottom of the screen, it is 26 across and 15 rows.
mono12

The robot screen printed numbers and letters with MONO 15 font. It shows A-T. On the bottom of the screen, it is 20 across and 12 rows.
mono15

The robot screen printed numbers and letters with MONO 20 font. It shows A-P. On the bottom of the screen, it is 16 across and 9 rows.
mono20

The robot screen printed numbers and letters with MONO 30 font. It shows A-K. On the bottom of the screen, it is 11 across and 6 rows.
mono30

The robot screen printed numbers and letters with MONO 40 font. It shows A-K. On the bottom of the screen, it is 8 across and 5 rows.
mono40

The robot screen printed numbers and letters with MONO 60 font. It shows 1-6. On the bottom of the screen, it is 3 rows.
mono60

The robot screen printed numbers and letters with PROP 20 font. It shows A-S. On the bottom of the screen, it is 8 across and 9 rows.
prop20

The robot screen printed numbers and letters with PROP 30 font. It shows A-M. On the bottom of the screen, it is 15 across and 6 rows.
prop30

The robot screen printed numbers and letters with PROP 40 font. It shows A-M. On the bottom of the screen, it is 15 across and 6 rows.
prop40

The robot screen printed numbers and letters with PROP 60 font. It shows 1-7. On the bottom of the screen, it is 7 across and 3 rows.
prop60

The robot screen printed numbers and letters with CJK 16 font. It shows 1-9 and A-Z. On the bottom of the screen, it is 43 across and 12 rows.
fontType::cjk16

Return Values

This function does not return a value.

Examples
// Print larger text
Brain.Screen.setFont(mono40);
Brain.Screen.print("VEX");

A screenshot of the V5 Brain showing the text "VEX" in larger font than the default.


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

A screenshot of the V5 Brain showing the text "VEX机器人" in Chinese font.

setPenWidth#

Sets the pen width used for drawing lines and shapes.

Available Functions
void setPenWidth(
  uint32_t width );

Parameters

Parameter

Type

Description

width

uint32_t

The pen width in pixels as a range from 0 to 32.

Return Values

This function does not return a value.

Notes Examples
// Draw a rectangle with a pen width of 10
Brain.Screen.setPenWidth(10);
Brain.Screen.drawRectangle(50, 50, 130, 60);

A screenshot of the V5 Brain showing a rectangle with thick borders.

setPenColor#

Sets the pen color used for drawing lines, shapes, and text.

Available Functions
1
void setPenColor(
  const color& color );
  • Sets the pen color using a predefined or custom color object
2
void setPenColor(
  const char *color );
  • Sets the pen color using a hexadecimal color value
3
void setPenColor(
  int hue );
  • Sets the pen color using a hue value
Parameters

Parameter

Type

Description

color

const color&

Sets the pen color using a color object. Predefined colors include:

  • black
  • white
  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan
  • transparent

color

const char*

Sets the pen color using a hexadecimal color value represented as a string (for example, “#FF0000”).

hue

int

Sets the pen color using an integer hue value in the range 0359, representing degrees around a color wheel (for example, 0 is red, 120 is green, and 240 is blue).

Return Values

This function does not return a value.

Notes
  • The default pen color at the start of a project is white.

  • The pen color is used for outlines of shapes (such as with drawCircle or drawRectangle), text and numeric output (with print and printAt), and individual pixels drawn with drawPixel.

  • The hue parameter 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°).

A color wheel showing the range of colors from 0 to 359, where red is 0, green is 120, and blue is 240.

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

A screenshot of the V5 Brain showing a rectangle with orange borders.

setFillColor#

Sets the fill color used when shapes are drawn.

Available Functions
1
void setFillColor(
  const color& color );
  • Sets the fill color using a predefined or custom color object
2
void setFillColor(
  const char *color );
  • Sets the fill color using a hexadecimal color value
3
void setFillColor(
  int hue );
  • Sets the fill color using a hue value
Parameters

Parameter

Type

Description

color

const color&

Sets the fill color using a color object. Predefined colors include:

  • black
  • white
  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan
  • transparent

color

const char

Sets the fill color using a hexadecimal color value represented as a string (for example, “#00FF00”).

hue

int

Sets the fill color using an integer hue value in the range 0359, representing degrees around a color wheel (for example, 0 is red, 120 is green, and 240 is blue).

Return Values

This function does not return a value.

Notes
  • The default fill color at the start of a project is black.

  • The fill color is used for interior of shapes (such as with drawCircle or drawRectangle).

  • The fill color is used as the background color for printed text (such as with print and printAt).

    • If transparent is used with printed text, the background will be black.

  • The hue parameter 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°).

A color wheel showing the range of colors from 0 to 359, where red is 0, green is 120, and blue is 240.

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

A screenshot of the V5 Brain showing a rectangle with filled with the color purple.

setOrigin#

Sets the origin used for drawing graphics on the Brain’s screen.

Available Functions
void setOrigin(
  int32_t x,
  int32_t y );

Parameters

Parameter

Type

Description

x

int32_t

The origin’s x-position relative to top left corner of the Brain’s screen from 0 to 480.

y

int32_t

The origin’s y-position relative to top left corner of the Brain’s screen from 0 to 480.

Return Values

This function does not return a value.

Notes
  • The 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, and printAt.

  • 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 Functions
void setClipRegion(
  int x,
  int y,
  int width,
  int height );

Parameters

Parameter

Type

Description

x

int

The x-coordinate of the top-left corner of the clip region, given as an integer from 0 to 480.

y

int

The y-coordinate of the top-left corner of the clip region, given as an integer from 0 to 240.

width

int

The width of the clip region in pixels, given as an integer from 0 to 480.

height

int

The height of the clip region in pixels, given as an integer from 0 to 240.

Return Values

This function does not return a value.

Notes
  • Drawing functions are still executed even if they fall outside the clip region, but only the portion inside the region is visible.

  • The x and y coordinates are relative to the current screen origin, which can be changed using setOrigin.

  • The clip region applies only to the current thread.

  • Setting a new clip region replaces any previously set clip region for the current thread.

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

The robot’s screen shows a cut off red rectangle with a thin white border and text saying "C-U-T-O-F" above the rectangle.

drawPixel#

Draws a single pixel on the V5 Brain screen at the specified x and y pixel location.

Available Functions
void drawPixel(
  int x,
  int y );

Parameters

Parameter

Type

Description

x

int

The x-coordinate where the pixel will be drawn, given as an integer from 0 to 480.

y

int

The y-coordinate where the pixel will be drawn, given as an integer from 0 to 240.

Return Values

This function does not return a value.

Notes
  • Pixels are drawn using the current pen color set with setPenColor.

  • The x and y coordinates are relative to the current screen origin, which can be set using setOrigin.

  • If the specified pixel location is outside the screen bounds, the pixel is not drawn.

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

A screenshot of the V5 Brain showing an assortment of pixels showing the corners of a square.

drawLine#

Draws a straight line connecting two points on the V5 Brain screen.

Available Functions
void drawLine(
  int x1,
  int y1,
  int x2,
  int y2 );

Parameters

Parameter

Type

Description

x1

int

The starting x-coordinate of the line, given as an integer from 0 to 480.

y1

int

The starting y-coordinate of the line, given as an integer from 0 to 240.

x2

int

The ending x-coordinate of the line, given as an integer from 0 to 480.

y2

int

The ending y-coordinate of the line, given as an integer from 0 to 240.

Return Values

This function does not return a value.

Notes
  • Lines 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 x and y coordinates are relative to the current screen origin, which can be set using setOrigin.

  • If any portion of the line lies outside the screen bounds, only the visible portion is drawn.

Examples
// Draw a line from the top left to bottom right of the screen
Brain.Screen.drawLine(0, 0, 479, 239);

The screen shows a thin diagonal line across the center, from the upper left corner to the lower right corner.

drawRectangle#

Draws a rectangle on the V5 Brain screen at the specified position and size.

Available Functions
1
void drawRectangle(
  int x,
  int y,
  int width,
  int height );
  • Fills the rectangle using the currently configured fill color
2
void drawRectangle(
  int x,
  int y,
  int width,
  int height,
  const color& color );
  • Fills the rectangle using a predefined or custom color object
3
void drawRectangle(
  int x,
  int y,
  int width,
  int height,
  const char* color );
  • Fills the rectangle using a hexadecimal color value
4
void drawRectangle(
  int x,
  int y,
  int width,
  int height,
  int hue );
  • Fills the rectangle using a hue value
Parameters

Parameter

Type

Description

x

int

The x-coordinate of the top-left corner of the rectangle, given as an integer from 0 to 480.

y

int

The y-coordinate of the top-left corner of the rectangle, given as an integer from 0 to 240.

width

int

The width of the rectangle, given as an integer from 0 to 480.

height

int

The height of the rectangle, given as an integer from 0 to 240.

color

const color&

Fills the rectangle using a color object. Predefined colors include:

  • black
  • white
  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan
  • transparent
This can also use a custom color object.

color

const char*

Fills the rectangle using a hexadecimal color value (for example, “#FF0000”).

hue

int

Fills the rectangle using a hue value in the range 0359.

Return Values

This function does not return a value.

Notes
  • The 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 color parameter is provided, the rectangle interior is filled using the current fill color set with setFillColor.

  • The x and y coordinates are relative to the current screen origin, which can be changed using setOrigin.

  • If any portion of the rectangle lies outside the screen bounds, only the visible portion is drawn.

  • The hue parameter 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°).

A color wheel showing the range of colors from 0 to 359, where red is 0, green is 120, and blue is 240.

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

The robot’s screen shows a rectangle with a thin white border on the screen.

drawCircle#

Draws a circle on the V5 Brain screen at the specified position and radius.

Available Functions
1
void drawCircle(
  int x,
  int y,
  int radius );
  • Fills the circle using the currently configured fill color
2
void drawCircle(
  int x,
  int y,
  int radius,
  const color& color );
  • Fills the circle using a predefined or custom color object
3
void drawCircle(
  int x,
  int y,
  int radius,
  const char* color );
  • Fills the circle using a hexadecimal color value
4
void drawCircle(
  int x,
  int y,
  int radius,
  int hue );
  • Fills the circle using a hue value
Parameters

Parameter

Type

Description

x

int

The x-coordinate of the center of the circle, given as an integer from 0 to 480.

y

int

The y-coordinate of the center of the circle, given as an integer from 0 to 240.

radius

int

The radius of the circle, given as an integer from 0 to 240 pixels.

color

const color&

Fills the circle using a color object. Predefined colors include:

  • black
  • white
  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan
  • transparent
This can also use a custom color object.

color

const char*

Fills the circle using a hexadecimal color value (for example, “#FF0000”).

hue

int

Fills the circle using a hue value in the range 0359.

Return Values

This function does not return a value.

Notes
  • The 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 color parameter is provided, the circle interior is filled using the current fill color set with setFillColor.

  • The x and y coordinates are relative to the current screen origin, which can be changed using setOrigin.

  • The hue parameter 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°).

A color wheel showing the range of colors from 0 to 359, where red is 0, green is 120, and blue is 240.

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

The robot’s screen shows a circle with a thin white border drawn in the center.

drawImageFromFile#

Draws an image on the V5 Brain screen using an image file stored on the SD card.

Available Functions
bool drawImageFromFile(
  const char* name,
  int x,
  int y );

Parameters

Parameter

Type

Description

name

const char*

The filename of the image on the SD card. The file must have a .bmp or .png extension.

x

int

The x-coordinate, in pixels from 0 to 480, at which the left edge of the image will be drawn.

y

int

The y-coordinate, in pixels from 0 to 240, at which the top edge of the image will be drawn.

Return Values

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).

Notes
  • Supported image formats are .bmp and .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 x and y coordinates are relative to the current screen origin, which can be changed using setOrigin.

Examples
// 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.

Available Functions
1
bool render();
  • Enables double buffering or renders the back buffer to the screen
2
bool render(
  bool bVsyncWait,
  bool bRunScheduler = true );
  • Controls how rendering waits for the display refresh
  • Optionally allows background tasks to run while waiting
Parameters

Parameter

Type

Description

bVsyncWait

bool

  • true — Wait for the screen’s vertical refresh before rendering to reduce visual tearing.
  • false — Do not wait for the screen’s vertical refresh before rendering.

bRunScheduler

bool

Optional.

  • true (default) — Allow background tasks to run while waiting to render.
  • false — Do not allow background tasks to run while waiting to render.

Return Values

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 render will require render to be used for the rest of the project.

    Examples
    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 Functions
bool pressing();

Parameters

This function does not accept any parameters.

Return Values

Returns 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 Functions
int32_t xPosition();

Parameters

This function does not accept any parameters.

Return Values

Returns an int32_t representing the x-coordinate, in pixels between 0 and 480, of the most recent screen press.

Examples
// 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 Functions
int32_t yPosition();

Parameters

This function does not accept any parameters.

Return Values

Returns an int32_t representing the y-coordinate, in pixels between 0 and 240, of the most recent screen press.

Examples
// 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
void pressed(
  void (*callback)(void) );
  • Calls a function when the screen is pressed
2
void pressed(
  void (*callback)(void*),
  void* arg );
  • Calls a function when the screen is pressed
  • Passes a user-defined value to the callback function
Parameters

Parameter

Type

Description

callback

void (*)(void)

A function that is called when the screen is pressed.

callback

void ()(void)

A function that is called when the screen is pressed and receives a user-defined argument.

arg

void*

A user-defined value that is passed to the callback function when the screen is pressed.

Return Values

This function does not return a value.

Notes
  • The callback function is executed each time the Brain screen is pressed.

  • Only one callback function can be registered at a time; calling pressed again replaces the previous callback.

  • The callback function must return void.

Examples
// 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
void released(
  void (*callback)(void) );
  • Calls a function when the screen is released after being pressed
2
void released(
  void (*callback)(void*),
  void* arg );
  • Calls a function when the screen is released after being pressed
  • Passes a user-defined value to the callback function
Parameters

Parameter

Type

Description

callback

void (*)(void)

A function that is called when the screen is released after being pressed.

callback

void ()(void)

A function that is called when the screen is released after being pressed and receives a user-defined argument.

arg

void*

A user-defined value that is passed to the callback function when the screen is released after being pressed.

Return Values

This function does not return a value.

Notes
  • The 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 released again replaces the previous callback.

  • The callback function must return void.

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