Screen#
Introduction#
The VEX AIR Drone Controller’s screen provides methods for displaying text, managing the cursor, drawing shapes, and handling touch interactions.
Below is a list of all available methods:
Cursor Print – Display text using a row/column system.
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.
get_row – Returns the current cursor row.
get_column – Returns the current cursor column.
XY Print – Display text at a specific screen coordinate.
print_at – Prints text at a specific x and y location.
set_origin – Sets a new origin for printing and drawing.
Mutators – Clear the screen or update visual settings.
clear_screen – Clears the screen of all drawings and text.
wait_for_render – Wait for drawing and print commands to render on the screen.
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.
Draw – Add graphics and images 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.
show_file – Displays an uploaded image.
Touch – Detect and respond to screen presses.
pressing – Returns whether the screen is currently being pressed.
x_position – Returns the x-coordinate where the screen is pressed.
y_position – Returns the y-coordinate where the screen is pressed.
Callback – Run functions when the screen is pressed or released.
Cursor Print#
print#
print
displays text on the controller’s screen at the current cursor position and font.
Usage:
controller.screen.print(text)
Parameters |
Description |
---|---|
|
The text, number, or variable value to display on the screen. |
|
Optional. The separator between printed text. By default, |
|
Optional. The string appended after the last printed text. By default, |
|
Optional. The number of decimals a float will print with as an integer. By default, |
# Display a message at the starting cursor position
controller.screen.print("Hello, VEX AIR!")
# Display the first 2 decimals of pi
controller.screen.print(3.1415, precision = 2)
set_cursor#
set_cursor
places the text cursor at a specific row and column on the screen. The number of rows and columns that fit depends on the selected font. With the default monospaced medium font, the screen can clearly display up to 11 rows and 53 columns. Text placed beyond this range may be cut off or harder 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 set_font
.
Usage:controller.screen.set_cursor(row, column)
Parameters |
Description |
---|---|
|
The row of the cursor. |
|
The column of the cursor. |
# Display text starting at Row 3 Column 2
controller.screen.set_cursor(3, 2)
controller.screen.print("Row 3, Column 2")
next_row#
next_row
moves the cursor to column 1 on the next row on the controller’s screen.
Usage:controller.screen.next_row()
Parameters |
Description |
---|---|
This method has no parameters. |
# Display two lines of text
controller.screen.print("Line 1")
controller.screen.next_row()
controller.screen.print("Line 2")
clear_row#
clear_row
clears a row of text on the controller’s screen.
Usage:controller.screen.clear_row(row, color)
Parameter |
Description |
---|---|
|
Optional. The row to clear. The default is the current cursor row. |
|
Optional. The color to apply to the cleared row. If a color is not specified, the
|
# Display text on two rows
controller.screen.print("This text stays")
controller.screen.next_row()
controller.screen.print("This text disappears")
# Wait 3 seconds before clearing only the second row
wait(3, SECONDS)
controller.screen.clear_row()
# Turn the 5th row green
controller.screen.clear_row(5, GREEN)
get_row#
row
returns the current row where text will be printed, as an integer.
Usage:controller.screen.get_row()
Parameters |
Description |
---|---|
This method has no parameters. |
# Set cursor to (3,2) and print row number
controller.screen.set_cursor(3, 2)
controller.screen.print(controller.screen.get_row())
get_column#
column
returns the current column where text will be printed, as an integer.
Usage:controller.screen.get_column()
Parameters |
Description |
---|---|
This method has no parameters. |
# Set cursor to (3,2) and print column number
controller.screen.set_cursor(3, 2)
controller.screen.print(controller.screen.get_column())
XY Print#
print_at#
print_at
displays text on the robot’s screen at a specific (x, y) position in pixels, using the currently set_font and set_origin. x
sets how far from the left side the text begins, and y
sets where the bottom of the letters sit. This method disregards the current cursor position.
Usage:
controller.screen.print_at(text, x, y)
Parameter |
Description |
---|---|
|
The text, number, or variable value to display on the screen. |
|
The horizontal position of the text, as an integer from 0 to 640 pixels. 0 is left; 640 is right. |
|
The vertical position of the text, as an integer from 0 to 480 pixels. 0 is the top; 480 is the bottom. |
# Display a message in the middle of the screen
controller.screen.print_at("Hello, drone!", x=230, y=240)
set_origin#
set_origin
sets the origin (0, 0) used for drawing or printing on the controller’s screen. By default, drawing or printing methods consider the top left corner of the screen as the origin. This method can reset the origin to an alternate (x, y) screen coordinate location.
Usage:
controller.screen.set_origin(x, y)
Parameter |
Description |
---|---|
|
The new x-coordinate to set as the origin, given as an integer from 0 to 640. |
|
The new y-coordinate to set as the origin, given as an integer from 0 to 480. |
# Set the origin to the center of the screen
controller.screen.set_origin(120, 120)
# Draw a rectangle at the new origin
controller.screen.draw_rectangle(0, 0, 80, 40)
Mutators#
clear_screen#
clear_screen
clears the controller’s screen of all drawings and text.
Usage:
controller.screen.clear_screen(row, column, color)
Parameter |
Description |
---|---|
|
Optional. The row to set the cursor at after clearing the screen. The default is 1. |
|
Optional. The column to set the cursor at after clearing the screen. The default is 1. |
|
Optional. Sets the screen color. To use, you must include all three optional parameters. Options include:
|
# Draw a circle, and clear it after 2 seconds
controller.screen.draw_circle(120, 120, 60)
wait(2, SECONDS)
controller.screen.clear_screen()
# Set the background color of the screen to red
controller.screen.clear_screen(color=RED)
wait_for_render#
wait_for_render
prevents any following commands from running until all previous drawing and print commands on the screen have finished rendering.
Usage:
controller.screen.wait_for_render()
Parameter |
Description |
---|---|
This method has no parameters. |
# Example coming soon
set_font#
set_font
sets the font used for displaying text on the controller’s screen. This font will apply to all text printed with print
or print_at
. The default font at the start of a project is MONO20
.
Usage:
controller.screen.set_font(fontname)
Parameter |
Description |
---|---|
|
Sets the font to one of the following:
|
|
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
# Display text using a larger font
controller.screen.set_font(MONO40)
controller.screen.print("VEX")
set_pen_width#
set_pen_width
sets the pen width used for drawing lines and shapes.
Usage:
controller.screen.set_pen_width(width)
Parameter |
Description |
---|---|
|
The pen width, given as an integer in pixels. |
# Draw a rectangle with a pen width of 10
controller.screen.set_pen_width(10)
controller.screen.draw_rectangle(50, 50, 130, 60)
set_pen_color#
set_pen_color
sets the pen color used for drawing lines, shapes, and printing text.
Usage:
controller.screen.set_pen_color(color)
Parameter |
Description |
---|---|
|
Optional. Sets the pen color. Options include:
|
# Draw a rectangle with a red pen
controller.screen.set_pen_color(RED)
controller.screen.draw_rectangle(50, 50, 130, 60)
set_fill_color#
set_fill_color
sets the fill color used when shapes are drawn.
Usage:controller.screen.set_fill_color(color)
Parameter |
Description |
---|---|
|
Optional. Sets the fill color. Options include:
|
# Draw two orange rectangles
controller.screen.set_fill_color(ORANGE)
controller.screen.draw_rectangle(50, 50, 100, 60)
controller.screen.draw_rectangle(50, 130, 100, 60)
Draw#
draw_pixel#
draw_pixel
draws a pixel at the specified (x, y) screen coordinate in the current pen color. It uses the current pen color set by set_pen_color
.
Usage:
controller.screen.draw_pixel(x, y)
Parameter |
Description |
---|---|
|
The x-coordinate where the pixel will be drawn, given as an integer from 0 to 640. |
|
The y-coordinate where the pixel will be drawn, given as an integer from 0 to 480. |
# Draw a pixel at the center of the screen
controller.screen.draw_pixel(120, 120)
draw_line#
draw_line
draws a line from the first specified screen coordinate (x1, y1)
to the second specified screen coordinate (x2, y2)
. It uses the current the pen width set by set_pen_width
and pen color set by set_pen_color
.
The x and y-coordinates use the default origin of (0, 0) unless a different origin has been set using set_origin
.
Usage:
controller.screen.draw_line(x1, y1, x2, y2)
Parameter |
Description |
---|---|
|
The starting x-coordinate of the line, given as an integer from 0 to 640. |
|
The starting y-coordinate of the line, given as an integer from 0 to 480. |
|
The ending x-coordinate of the line, given as an integer from 0 to 640. |
|
The ending y-coordinate of the line, given as an integer from 0 to 480. |
# Draw a line from the top left to bottom right of the screen
controller.screen.draw_line(0, 0, 640, 480)
draw_rectangle#
draw_rectangle
draws a rectangle with its top-left corner at the specified (x, y)
coordinate and a size determined by the given width and height, all measured in pixels. The rectangle’s outline is drawn using the current pen width set by set_pen_width
and the pen color set by set_pen_color
. The interior is filled with the color set by set_fill_color
.
The x and y-coordinates use the default origin of (0, 0) unless a different origin has been set using set_origin
.
Usage:controller.screen.draw_rectangle(x, y, width, height, color)
Parameter |
Description |
---|---|
|
The x-coordinate of the top-left corner of the rectangle, given as an integer from 0 to 640. |
|
The y-coordinate of the top-left corner of the rectangle, given as an integer from 0 to 480. |
|
The width of the rectangle, given as an integer from 0 to 640. |
|
The height of the rectangle, given as an integer from 0 to 480. |
|
Optional. Sets the outline color of the rectangle. Options include:
|
# Draw a red rectangle on the screen
controller.screen.draw_rectangle(50, 50, 130, 60, RED)
draw_circle#
draw_circle
draws a circle with its center at the specified (x, y)
coordinate and a size determined by the given radius, all measured in pixels. The circle’s outline is drawn using the current pen width set by set_pen_width
and the pen color set by set_pen_color
. The interior is filled with the color set by set_fill_color
.
The x and y-coordinates use the default origin of (0, 0) unless a different origin has been set using set_origin
.
Usage:controller.screen.draw_circle(x, y, radius, color)
Parameter |
Description |
---|---|
|
The x-coordinate of the center of the circle, given as an integer from 0 to 640. |
|
The y-coordinate of the center of the circle, given as an integer from 0 to 480. |
|
The radius of the circle, given as an integer from 0 to 480 pixels. |
|
Optional. The outline color of the circle. Options include:
|
# Draw a green circle on the screen
controller.screen.draw_circle(120, 120, 40, GREEN)
show_file#
show_file
draws a custom uploaded image on the controller’s screen, with its position set using the x
, y
, and center
parameters based on the image’s reference point.
Usage:
controller.screen.show_file(file, x, y, center)
Parameter |
Description |
---|---|
|
The custom image to use, from |
|
The horizontal offset for the image, given as an integer in pixels. Positive values move it right; negative values move it left. |
|
The vertical offset for the image, given as an integer in pixels. Positive values move it down; negative values move it up. |
|
Optional. If |
# Display uploaded Image 1 in the top left corner
controller.screen.show_file(IMAGE1, 0, 0)
# Display the same image on both sides of the screen
controller.screen.show_file(IMAGE1, 65, 0, center=True)
controller.screen.show_file(IMAGE1, -65, 0, center=True)
Touch#
pressing#
pressing
returns whether the controller’s screen is currently being pressed as a Boolean:
True
– The screen is being pressed.False
– The screen is not being pressed.
Usage:
controller.screen.pressing()
Parameters |
Description |
---|---|
This method has no parameters. |
# Example coming soon
x_position#
x_position
returns the x-coordinate in pixels where the screen was pressed, as an integer from 0 (left) to 640 (right).
Usage:controller.screen.x_position()
Parameters |
Description |
---|---|
This method has no parameters. |
# Report the x-coordinate of where the screen is pressed.
while True:
if controller.screen.pressing():
controller.screen.clear_screen()
controller.screen.set_cursor(1, 1)
controller.screen.print(controller.screen.x_position())
wait (50, MSEC)
y_position#
y_position
returns the y-coordinate in pixels where the screen was pressed, as an integer from 0 (top) to 480 (bottom).
Usage:controller.screen.y_position()
# Report the y-coordinate of where the screen is pressed.
while True:
if controller.screen.pressing():
controller.screen.clear_screen()
controller.screen.set_cursor(1, 1)
controller.screen.print(controller.screen.y_position())
wait (50, MSEC)
Callback#
pressed#
pressed
registers a method to be called when the controller’s screen is pressed.
Usage:
controller.screen.pressed(callback, arg)
Parameters |
Description |
---|---|
|
A function that is previously defined to execute when the axis’ value changes. |
|
Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information. |
# Example coming soon
released#
released
registers a method to be called when the screen is no longer being pressed.
Usage:
controller.screen.released(callback, arg)
Parameters |
Description |
---|---|
|
A function that is previously defined to execute when the axis’ value changes. |
|
Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information. |
# Example coming soon