Screen#

Introduction#

The Screen category 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.

Below is a list of all methods:

Cursor Print – Place and print text.

  • print – Prints text at the current cursor position.

  • set_cursor – Sets 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 current cursor row.

  • column – Returns the current cursor column.

  • print_at – Prints text at a specific x and y location.

  • get_string_width – Returns the width of a string in pixels.

  • get_string_height – Returns the height of a string in pixels.

  • 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 for drawn shapes and lines.

  • set_pen_color – Sets the color for outlines and text.

  • set_fill_color – Sets the fill color for shapes and backgrounds.

  • set_origin – Sets a new origin for printing and drawing.

Draw – Add graphics to the screen.

  • draw_pixel – Draws a pixel at a specific x and y position.

  • draw_line – Draws a line between two points.

  • draw_rectangle – Draws a rectangle.

  • draw_circle – Draws a circle.

  • render – Updates the Brain’s screen with text and drawings only when called.

  • set_clip_region – Restricts where drawings and text can appear.

Touch – Get touch input from the screen.

  • pressing – Returns whether the screen is being pressed.

  • x_position – Returns the X coordinate of the last screen event.

  • y_position – Returns the Y coordinate of the last screen event.

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 on the screen using the current cursor position.

Usage:

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

Parameters

Description

text

The text 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 Screen" printed on the screen.

set_cursor#

set_cursor sets the cursor position. The cursor is placed at a specific row and column on the screen. 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 of the cursor.

column

The column of the cursor.

# 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 on the screen.

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 showing the text "Line 1" printed above "Line 2".

clear_row#

clear_row(row, color) clears a row to a single color.

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 current row as an integer where text will be printed.

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 showing the text "3" on row 3.

column#

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

Usage:

brain.screen.column()

Parameters

Description

This method has no parameters.

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

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

get_string_width#

get_string_width(string) gets the width of a string in pixels as an integer as if it was on the Brain’s screen. The width of a string changes based on the length of the string and the size of the font.

Usage:

brain.screen.get_string_width(string)

Parameters

Description

string

The string to measure.

get_string_height#

get_string_height(string) gets the height of a string as an integer in pixels as if it was on the Brain’s screen. The height of a string changes based on the length of the string and the size of the 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 a new line.

Usage:

brain.screen.new_line()

Parameters

Description

This method has no parameters.

Mutators#

clear_screen#

clear_screen(color) clears the whole Brain’s screen to a single color.

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 Brain's screen
brain.screen.print("VEXcode")

# Clear screen to black
brain.screen.clear_screen()

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

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

A screenshot of the V5 Brain with a blue screen.

set_font#

set_font(fontname) sets the font type used for printing text on the Brain’s screen.

Usage:

brain.screen.set_font(font)

Parameters

Description

font

A valid font option 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.
FontType.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.
FontType.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.
FontType.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.
FontType.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.
FontType.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.
FontType.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.
FontType.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.
FontType.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.
FontType.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.
FontType.PROP60

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

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

set_pen_width#

set_pen_width(width) sets the pen width used for drawing lines, rectangles, and circles.

Usage:

brain.screen.set_pen_width(value)

Parameters

Description

value

The pen width in pixels in a range 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 showing a rectangle with thick borders.

set_pen_color#

set_pen_color sets the pen color used for drawing lines, rectangles, and circles.

Usage:

brain.screen.set_pen_color(color)

Parameters

Description

color

A valid color option:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.TRANSPARENT
  • Color.WHITE
# 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 showing a rectangle with orange borders.

set_fill_color#

set_fill_color sets the fill color used for drawing rectangles and circles.

Usage:

brain.screen.set_fill_color(color)

Parameters

Description

color

A valid color option:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.TRANSPARENT
  • Color.WHITE
# 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 showing a rectangle filled with purple.

set_origin#

set_origin sets the origin used for drawing graphics on the Brain’s screen. Drawing functions consider the top left corner of the Brain’s screen as the origin. This function can move the origin to an alternate position such as the center of the Brain’s screen.

Usage:

brain.screen.set_origin(x, y)

Parameters

Description

x

The origin’s x position relative to top left corner.

y

The origin’s y position relative to top left corner.

Draw#

draw_pixel#

draw_pixel draws a pixel using the current pen color.

Usage:

brain.screen.draw_pixel(x, y)

Parameters

Description

x

The x position to draw the pixel referenced to the screen origin.

y

The y position to draw the pixel 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 showing an assortment of pixels showing the corners of a square.

draw_line#

draw_line draws a line using the current pen color.

Usage:

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

Parameters

Description

start_x

The x position of the start of the line referenced to the screen origin.

start_y

The y position of the start of the line referenced to the screen origin.

end_x

The x position of the end of the line referenced to the screen origin.

end_y

The y position of the end of the line 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)

The 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 on the screen using the current pen and fill colors.

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
# Draw a rectangle on the screen
brain.screen.draw_rectangle(50, 50, 130, 60)

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

draw_circle#

draw_circle(x, y, radius, color) draws a circle using the current pen and fill colors.

Usage:

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

Parameters

Description

x

The x position of the circle center referenced to the screen origin.

y

The y position of the circle center referenced to the screen origin.

radius

The radius of the circle.

color

Optional. A valid color option:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.TRANSPARENT
  • Color.WHITE
# Draw a circle on the screen
brain.screen.draw_circle(120, 120, 40)

The robot’s 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 sets the clip region for drawing the supplied rectangle.

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.

Touch#

pressing#

pressing returns whether the screen is currently being pressed (touched).

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

x_position#

x_position returns the X coordinate of the last screen event, press or release as an integer.

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 event, press or release as an integer.

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)