Screen#

Introduction#

The Screen methods control how the V5 Brain shows text, numbers, and graphics on its touchscreen, and how it responds 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 480 x 240 pixels.

The V5 Brain screen with red grid lines showing the layout of 12 rows and 48 columns in total. The pixel dimensions are 479 wide by 239 tall. The upper left corner begins at (0,0) pixels and row 1, column 1, while the lower right corner ends at (479, 239) pixels and row 12, column 48.

Below is a list of all methods:

Cursor Print — Place and print text.

  • print — Prints text, numbers, or variable values at the current cursor position.

  • set_cursor — Moves the cursor to a specific row and column.

  • next_row — Moves the cursor to column 1 of the next row.

  • clear_row — Clears a row of text.

  • row — Returns the row where text will be printed.

  • column — Returns the column where text will be printed.

  • print_at — Prints text, numbers, or variable values at a specific x and y coordinate.

  • get_string_width — Returns the width of a string in pixels using the current font.

  • get_string_height — Returns the height of a string in pixels using the current font.

  • clear_line — Clears a line of text.

  • new_line — Moves the cursor to a new line.

Mutators — Change screen settings, colors, and drawing behavior.

  • clear_screen — Clears the screen of all drawings and text.

  • set_font — Sets the font for printed text.

  • set_pen_width — Sets the thickness of drawn lines and shape outlines.

  • set_pen_color — Sets the color of text, pixels, lines, and shape outlines.

  • set_fill_color — Sets the fill color for drawn shapes and printed text backgrounds.

  • set_origin — Sets the origin used for coordinate-based printing and drawing.

Draw — Add graphics to the screen.

Getters — Check touch state and touch position.

  • pressing — Returns whether the screen is being pressed.

  • x_position — Returns the x-coordinate of the last screen press.

  • y_position — Returns the y-coordinate of the last screen press.

Callbacks — Respond to touch events on the screen.

  • pressed — Registers a function to be called when the screen is pressed.

  • released — Registers a function to be called when the screen is released.

For information on constructing a Brain to gain access to the screen methods, see Brain.

Cursor Print#

print#

print prints text, numbers, or variable values on the Brain screen at the current cursor position and font.

Usage:

brain.screen.print(text, sep, precision)

Parameters

Description

text

The text, number, or variable value to print.

sep

Optional. A string to insert between values. This must be written as a keyword argument (sep=). The default is “”.

precision

Optional. The number of decimal places to display when printing simple numbers. This must be written as a keyword argument(precision=). The default is 2.

# Print on the Brain's screen
brain.screen.print("Hello, Robot!")

A screenshot of the V5 Brain showing "Hello Robot" printed on the screen in the upper left corner in white text.

set_cursor#

set_cursor moves the cursor to a specific row and column on the Brain screen. The next print call will start printing at that location. How many rows and columns can comfortably fit depends on the selected font. With the default monospaced medium font, up to 8 rows and 13 columns can be displayed clearly. Text placed beyond this range may be cut off or become difficult to read.

Monospaced fonts have characters that are all the same width, making text placement consistent. In contrast, proportional fonts vary in character width, so some letters take up more space than others. However, regardless of which type is used, set_cursor positions the cursor based on row and column size, not font style. The font size can be adjusted using the set_font.

Usage:

brain.screen.set_cursor(row, column)

Parameters

Description

row

The row to move the cursor to.

column

The column to move the cursor to.

# Display text starting at Row 3 Column 12
brain.screen.set_cursor(3, 12)
brain.screen.print("Row 3, Column 12")

A screenshot of the V5 Brain showing Row 3 Column 12 printed in the upper portion near the center of screen, at that position.

next_row#

next_row moves the cursor to the next row.

Usage:

brain.screen.next_row()

Parameters

Description

This method has no parameters.

# Print two lines of text on the Brain's screen
brain.screen.print("Line 1")
brain.screen.next_row()
brain.screen.print("Line 2")

A screenshot of the V5 Brain screen showing two lines of white text in the upper left corner. The top line reads Line 1, and the second line directly below it reads Line 2.

clear_row#

clear_row clears a single row of text on the Brain screen.

Usage:

brain.screen.clear_row(row, color)

Parameters

Description

row

Optional. The row to clear. The default is the current cursor row.

color

Optional. A valid color, a hex value, or a web string.

# Only keep the text on row 1
brain.screen.print("This text stays")
brain.screen.next_row
brain.screen.print("This text disappears")
wait(3, SECONDS)

brain.screen.clear_row()

row#

row returns the row where text will be printed as an integer.

Usage:

brain.screen.row()

Parameters

Description

This method has no parameters.

# Display the cursor's current row
brain.screen.set_cursor(3, 2)
brain.screen.print(brain.screen.row())

A screenshot of the V5 Brain screen showing the text 3 in white in the upper left quadrant of the screen, at the row 3 column 2 position.

column#

column returns the column where text will be printed as an integer.

Usage:

brain.screen.column()

Parameters

Description

This method has no parameters.

# Display the cursor's current column
brain.screen.set_cursor(3, 15)
brain.screen.print(brain.screen.column())

A screenshot of the V5 Brain screen showing the text 15 in white in the upper left quadrant of the screen, at the row 3 column 15 position.

get_string_width#

get_string_width returns the width of a string in pixels as an integer, using the current font.

Usage:
brain.screen.get_string_width(string)

Parameters

Description

string

The string to measure.

get_string_height#

get_string_height returns the height of a string in pixels as an integer, using the current font.

Usage:
brain.screen.get_string_height(string)

Parameters

Description

string

The string to measure.

clear_line#

clear_line clears the current row of text.

Usage: brain.screen.clear_line()

Parameters

Description

This method has no parameters.

new_line#

new_line moves the cursor to column 1 on the next row on the Brain screen.

Usage:

brain.screen.new_line()

Parameters

Description

This method has no parameters.

Mutators#

clear_screen#

clear_screen clears all drawings and text from the Brain screen.

Usage:

brain.screen.clear_screen(color)

Parameters

Description

color

Optional. A valid color option:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.BLACK (Default)
  • Color.WHITE

# Print VEXcode on the screen
brain.screen.print("VEXcode")
wait(2, SECONDS)
# Clear screen to black
brain.screen.clear_screen()

# Print VEXcode on the screen
brain.screen.print("VEXcode")

# Clear screen to blue using predefined color
brain.screen.clear_screen(Color.BLUE)

A screenshot of the V5 Brain screen with the entire printable area in bright blue.

set_font#

set_font sets the font used for displaying text on the Brain screen. This font will apply to all text printed after this method runs.

Usage:

brain.screen.set_font(font)

Parameters

Description

font

A valid font option below.

A screenshot of the V5 Brain screen with numbers and letters printed in white in the upper left corner in MONO 12 font. It shows A-Z on one line, across about a quarter of the width of screen. In the bottom left corner it reads 80 columns and 20 rows.
FontType.MONO12

The same image as the one previous, with Mono 15 font. It shows A-Z on one line, across nearly half width of the screen. In the bottom left corner it reads 68 columns and 16 rows.
FontType.MONO15

The same image as the one previous, with Mono 20 font. It shows A-Z on one line, across nearly two thirds of the width of the screen. In the bottom left corner it reads 48 columns and 12 rows.
FontType.MONO20

The same image as the one previous, with Mono 30 font. It shows A-Z on one line, across nearly the whole width of the screen. In the bottom left corner it reads 32 columns and 8 rows.
FontType.MONO30

The same image as the one previous, with Mono 40 font. It shows A-X on one line, spanning the width the screen. In the bottom left corner it reads 24 columns and 6 rows.
FontType.MONO40

The same image as the one previous, with Mono 60 font. It shows A-P on one line, spanning the width the screen. On the bottom it reads 16 columns and 4 rows.
FontType.MONO60

The same image as the one previous, with Prop 20 font. It shows A-Z on one line, across nearly two thirds of the width of the screen. In the bottom left corner it reads 48 columns and 12 rows.
FontType.PROP20

The same image as the one previous, with Prop 30 font. It shows A-Z on one line, spanning nearly the width of the screen. In the bottom left corner it reads 32 columns and 8 rows.
FontType.PROP30

The same image as the one previous, with Prop 40 font. It shows A-U on one line, spanning the width of the screen. In the bottom left corner it reads 24 columns and 6 rows.
FontType.PROP40

The same image as the one previous, with Prop 60 font. It shows A-N on one line, spanning the width of the screen. On the bottom it reads 15 columns and 4 rows.
FontType.PROP60

# Set the font type to MONO40
brain.screen.set_font(FontType.MONO40)
brain.screen.print("VEX")

A screenshot of the V5 Brain screen reads VEX in white in the upper left corner, in larger font than the default.

set_pen_width#

set_pen_width sets the thickness of drawn lines and shape outlines.

Usage:

brain.screen.set_pen_width(value)

Parameters

Description

value

The pen width, in pixels, from 0 to 32.

# Draw a rectangle with a pen width of 10
brain.screen.set_pen_width(10)
brain.screen.draw_rectangle(50, 50, 130, 60)

A screenshot of the V5 Brain screen showing a rectangle with thick borders printed in the upper left quadrant of the screen.

set_pen_color#

set_pen_color sets the color of text, pixels, lines, and shape outlines.

Usage:

brain.screen.set_pen_color(color)

Parameters

Description

color

The pen and font color to use. Options include:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.TRANSPARENT
  • Color.WHITE
You can also specify a custom color.

# Draw a rectangle with orange borders
brain.screen.set_pen_color(Color.ORANGE)
brain.screen.draw_rectangle(50, 50, 130, 60)

A screenshot of the V5 Brain screen showing a rectangle drawn in orange in the upper left quadrant of the screen.

set_fill_color#

set_fill_color sets the fill color used when shapes are drawn.

Usage:

brain.screen.set_fill_color(color)

Parameters

Description

color

The fill color to use. Options include:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.TRANSPARENT
  • Color.WHITE
You can also specify a custom color.

# Draw a purple rectangle
brain.screen.set_fill_color(Color.PURPLE)
brain.screen.draw_rectangle(50, 130, 100, 60)

A screenshot of the V5 Brain screen showing a rectangle filled with purple in the lower left quadrant of the screen.

set_origin#

set_origin sets the origin used for drawing and coordinate-based printing on the Brain screen. By default, the origin is the top-left corner of the screen.

Usage:

brain.screen.set_origin(x, y)

Parameters

Description

x

The x-coordinate to set as the origin, from 0 to 479.

y

The y-coordinate to set as the origin, from 0 to 239.

Draw#

draw_pixel#

draw_pixel draws one pixel at the selected x and y coordinate using the current pen color.

Usage:

brain.screen.draw_pixel(x, y)

Parameters

Description

x

The x-coordinate to draw the pixel, from 0 to 479, referenced to the screen origin.

y

The y-coordinate to draw the pixel, from 0 to 239, referenced to the screen origin.

# Draw the pixels marking the corners of a square
brain.screen.draw_pixel(250, 100)
brain.screen.draw_pixel(275, 100)
brain.screen.draw_pixel(250, 125)
brain.screen.draw_pixel(275, 125)

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

draw_line#

draw_line draws a line from the first screen coordinate to the second screen coordinate using the current pen width and pen color.

Usage:

brain.screen.draw_line(start_x, start_y, end_x, end_y)

Parameters

Description

start_x

The x-coordinate in pixels of the start of the line, from 0 to 479, referenced to the screen origin.

start_y

The y-coordinate in pixels of the start of the line, from 0 to 239, referenced to the screen origin.

end_x

The x-coordinate in pixels of the end of the line, from 0 to 479, referenced to the screen origin.

end_y

The y-coordinate in pixels of the end of the line, from 0 to 239, referenced to the screen origin.

# Draw a line from the top left to bottom right of the screen
brain.screen.draw_line(0, 0, 479, 239)

A screenshot of the V5 Brain screen shows a thin diagonal line across the center, from the upper left corner to the lower right corner.

draw_rectangle#

draw_rectangle draws a rectangle using the current pen width, pen color, and fill color, unless the optional color parameter is used.

Usage:

brain.screen.draw_rectangle(x, y, width, height, color)

Parameters

Description

x

The x-coordinate in pixels of the top-left corner of the rectangle from 0 to 479.

y

The y-coordinate in pixels of the top-left corner of the rectangle from 0 to 239.

width

The width of the rectangle.

height

The height of the rectangle.

color

Optional. A valid color option:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.TRANSPARENT
  • Color.WHITE
You can also specify a custom color.

# Draw a rectangle on the screen
brain.screen.draw_rectangle(50, 50, 130, 60)

A screenshot of the V5 Brain's screen shows a rectangle with a thin white border printed in the upper left quadrant.

draw_circle#

draw_circle draws a circle using the current pen width, pen color, and fill color, unless the optional color parameter is used.

Usage:

brain.screen.draw_circle(x, y, radius, color)

Parameters

Description

x

The x-coordinate in pixels of the center of the circle, from 0 to 479, referenced to the screen origin.

y

The y-coordinate in pixels of the center of the circle, from 0 to 239, referenced to the screen origin.

radius

The radius of the circle, in pixels.

color

Optional. The fill color to use. Options include:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.TRANSPARENT
  • Color.WHITE
You can also specify a custom color.

# Draw a circle on the screen
brain.screen.draw_circle(120, 120, 40)

A screenshot of the V5 Brain screen shows a circle with a thin white border drawn in the center.

render#

render enables double buffering for the Brain’s screen. Once called, any drawing commands (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.

Usage:

brain.screen.render()

Parameters

Description

This method has no parameters.

# Render text after moving
brain.screen.render()
brain.screen.print("Render later...")
drivetrain.drive_for(FORWARD, 100, MM)
drivetrain.turn_for(RIGHT, 90, DEGREES)
brain.screen.render()

set_clip_region#

set_clip_region defines a rectangular area on the screen where all drawings and text will be confined. Any content outside this region will not be displayed.

Usage:

brain.screen.set_clip_region(x, y, width, height)

Parameters

Description

x

The x position of the top-left corner of the rectangle, referenced to the screen origin.

y

The y position of the top-left corner of the rectangle, referenced to the screen origin.

width

The width of the rectangle.

height

The height of the rectangle.

# Restrict text and drawings to a specific region
brain.screen.set_clip_region(0, 0, 120, 120)
brain.screen.draw_rectangle(60, 60, 100, 100, Color.RED)
brain.screen.print_at("Cut off!", x=60, y=60)

A screenshot of the V5 Brain screen with white text that read Cut of with a solid red square directly beneath it, in the upper left quadrant of the screen showing what prints within the clip region.

Touch#

pressing#

pressing returns a Boolean indicating whether the Brain screen is currently being pressed.

  • True - The screen is being pressed.

  • False - The screen is not being pressed.

Usage:

brain.screen.pressing()

Parameters

Description

This method has no parameters.

# Change the screen's color after it's pressed
while not brain.screen.pressing():
    wait(5, MSEC)
brain.screen.set_fill_color(Color.GREEN)
brain.screen.draw_rectangle(0, 0, 479, 239)

# Display different messages after the screen is pressed
while not brain.screen.pressing():
    wait(5, MSEC)
brain.screen.print("First message!")
brain.screen.next_row()
# Lift finger to press the screen again
while brain.screen.pressing():
    wait(5, MSEC)
while not brain.screen.pressing():
    wait(5, MSEC)
brain.screen.print("Second message!")
brain.screen.next_row()

x_position#

x_position returns the x-coordinate of the last screen press as an integer from 0 (left) to 479 (right).

Usage:

brain.screen.x_position()

Parameters

Description

This method has no parameters.

# Display a circle where the screen is pressed
while not brain.screen.pressing():
    wait(5, MSEC)
brain.screen.set_fill_color(Color.WHITE)
brain.screen.draw_circle(brain.screen.x_position(), brain.screen.y_position(), 20)

y_position#

y_position returns the y-coordinate of the last screen press as an integer from 0 (top) to 239 (bottom).

Usage:

brain.screen.y_position()

Parameters

Description

This method has no parameters.

# Display a circle where the screen is pressed
while not brain.screen.pressing():
    wait(5, MSEC)
brain.screen.set_fill_color(Color.WHITE)
brain.screen.draw_circle(brain.screen.x_position(), brain.screen.y_position(), 20)

Callbacks#

pressed#

pressed registers a function to be called when the Brain’s Screen is pressed.

Usage:

brain.screen.pressed(callback, arg)

Parameters

Description

callback

A previously defined function that executes when the Brain screen is pressed.

arg

Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information.

def my_function():
  brain.screen.print("Screen pressed")

# Call my_function whenever the Brain screen is pressed
brain.screen.pressed(my_function)

released#

released registers a function to be called when the screen is released (touch removed).

Usage:

brain.screen.released(callback, arg)

Parameters

Description

callback

A previously defined function that executes when the Brain screen is released.

arg

Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information.

def my_function():
  brain.screen.print("Screen released")

# Call my_function whenever the Brain screen is released
brain.screen.released(my_function)