The Brain
class provides access to the VEX V5 brain's built-in components, including the screen, battery, and SD card. This is the central hub for interacting with the robot's onboard hardware.
vex.Brain
The Brain class creates a number of instances of internal classes that allow access\ to the screen, battery, 3wire ports and sd card on the V5 brain.
None
An instance of the Brain class
brain = Brain()
battery = Brain.Battery()
An instance of the Battery class
screen = Brain.Lcd()
An instance of the Lcd class
sdcard = Brain.Sdcard()
An instance of the Sdcard class
three_wire_port = Triport(Ports.PORT22)
An instance of the Triport (3wire) class
timer = Timer()
An instance of the Timer class
Battery
None
Instance of Battery class
capacity()
None
capacity as percentage
current(units=CurrentUnits.AMP)
units (optional) : AMP, default is mA but jot available as an enum.
current in supplied units
temperature(units=PercentUnits.PERCENT)
units (optional) : PERCENT, CELSIUS or FAHRENHEIT, default is CELSIUS
temperature in supplied units
voltage(units=VoltageUnits.MV)
units (optional) : VOLTS or MV, default is MV
voltage in supplied units
Lcd
A class used to access to screen on the V5 for drawing and receiving touch events.
None
An instance of the Brain.Lcd class
clear_row(number=None, color=Color.BLACK)
The color can be passed in similar ways to the Color class.\
row (optional) : The row to clear, default is current cursor row
color (optional) : The color the screen will be set to, default is BLACK
None
# clear row to black\
brain.screen.clear_row()
# clear row 2 to red\
brain.screen.clear_row(2, Color.RED)
clear_screen(color=Color.BLACK)
The color can be passed in similar ways to the Color class.\
color (optional) : The color the screen will be set to, default is BLACK
None
# clear screen to black\
brain.screen.clear_screen()
# clear screen to blue using predefined color\
brain.screen.clear_screen(Color.BLUE)
column()
Return the current column where text will be printed
draw_circle(x, y, radius, color=None)
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 height of the circle.
color (optional) : An optional fill color, the current fill color will be used if not supplied
None
# draw a green circle on the screen that is filled using blue\
brain.screen.set_pen_color(Color.GREEN)\
brain.screen.set_fill_color(Color.BLUE)\
brain.screen.draw_circle(50, 50, 10)
# draw a green circle on the screen that is filled using red\
brain.screen.set_pen_color(Color.GREEN)\
brain.screen.draw_circle(100, 50, 10, Color.RED)
draw_image_from_file(filename, x, y)
filename : The file name of the image.
x : The X coordinate for the top left corner of the image on the screen
y : The Y coordinate for the top left corner of the image on the screen
True if successfully drawn, False on error
# draw the vex.bmp image on the screen at coordinate 0, 0\
# an image named vex.bmp must be on the SD Card in the root folder\
brain.screen.draw_image_from_file('vex.bmp', 0, 0)
draw_line(x1, y1, x2, y2)
x1 : The x position of the beginning of the line referenced to the screen origin.
y1 : The y position of the beginning of the line referenced to the screen origin.
x2 : The x position of the end of the line referenced to the screen origin.
y2 : The y position of the end of the line referenced to the screen origin.
None
# draw a red line on the screen\
brain.screen.set_pen_color(Color.RED)\
brain.screen.draw_line(10, 10, 20, 20)
draw_pixel(x, y)
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.
None
# draw a red pixel on the screen\
brain.screen.set_pen_color(Color.RED)\
brain.screen.draw_pixel(10, 10)
draw_rectangle(x, y, width, height, color=None)
x : The x position of the rectangle top/left corner referenced to the screen origin.
y : The y position of the rectangle top/left corner referenced to the screen origin.
width : The width of the rectangle.
height : The height of the rectangle.
color (optional) : An optional fill color, the current fill color will be used if not supplied
None
# draw a green rectangle on the screen that is filled using blue\
brain.screen.set_pen_color(Color.GREEN)\
brain.screen.set_fill_color(Color.BLUE)\
brain.screen.draw_rectangle(10, 10, 20, 20)
# draw a green rectangle on the screen that is filled using red\
brain.screen.set_pen_color(Color.GREEN)\
brain.screen.draw_rectangle(50, 50, 20, 20, Color.RED)
get_string_height(*args)
arguments are in the same format as can be passed to the print function.
height of string as integer.
get_string_width(*args)
arguments are in the same format as can be passed to the print function.
width of string as integer.
next_row()
None
None
pressed(callback, arg=())
callback : A function that will be called when the screen is pressed
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("screen pressed")
brain.screen.pressed(foo)
pressing()
None
True or False
print(*args, **kwargs)
Optional keyword arguments:
sep : string inserted between values, default a space.
precision : the number of decimal places to display when printing simple numbers, default is 2
None
# print the number 1 on the screen at current cursor position\
brain.screen.print(1)
# print the numbers 1, 2, 3 and 4 on the screen at current cursor position separated by a '-'\
brain.screen.print(1, 2, 3, 4, sep='-')
# print motor1 velocity on the screen using a format string\
brain.screen.print("motor 1 : % 7.2f" %(motor1.velocity()))
print_at(*args, **kwargs)
Required keyword arguments
x : The x position of the text referenced to the screen origin.
y : The y position of the text referenced to the screen origin.
Optional keyword arguments:
sep : string inserted between values, default a space.
precision : the number of decimal places to display when printing simple numbers, default is 2
opaque : text does not clear background pixels if set to False. default is True.
None
# print the number 1 on the screen at position x=100, y=40\
brain.screen.print_at(1, x=100, y=40)
# print the numbers 1, 2, 3 and 4 on the screen at position x=100, y=40\
brain.screen.print_at(1, 2, 3, 4, x=100, y=40)
# print motor1 velocity on the screen using a format string at position x=100, y=40\
brain.screen.print_at("motor 1 : % 7.2f" %(motor1.velocity()), x=100, y=40)
released(callback, arg=())
callback : A function that will be called when the screen is released
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("screen released")
brain.screen.released(foo)
render()
Once called, further drawing will not appear on the screen until the next time\ render is called. This function will block until the screen can be updated.
None
True if buffer was successfully rendered to screen.
row()
Return the current row where text will be printed
set_clip_region(x, y, width, height)
All drawing is clipped to the given rectangle.\ This is set on a per thread basis.
x : The x position of the rectangle top/left corner referenced to the screen origin.
y : The y position of the rectangle top/left corner referenced to the screen origin.
width : The width of the rectangle.
height : The height of the rectangle.
None
set_cursor(row, col)
row and column spacing will take into account the selected font.\ The base cell size if 10x20 pixels for the MONO20 font.\ text may not accurately print if using a proportional font.\ The top, left corner of the screen is position 1,1
row : The cursor row
col : The cursor column
None
set_fill_color(color)
The color can be passed in similar ways to the Color class.\ The color is specific to the running thread.
color : The fill color
None
# set pen color red using a hex value\
brain.screen.set_fill_color(0xFF0000)
# set pen color blue using predefined color\
brain.screen.set_fill_color(Color.BLUE)
# set pen color green using web string\
brain.screen.set_fill_color("#00FF00")
set_font(fontname)
fontname : The font name
None
brain.screen.font_type(FontType.MONO40)
set_origin(x, y)
drawing functions consider the top left corner of the screen as the origin.\ This function can move the origin to an alternate position such as the center of the screen.
x : The origins x position relative to top left corner
y : The origins y position relative to top left corner
None
set_pen_color(color)
The color can be passed in similar ways to the Color class.\ The color is specific to the running thread.
color : The pen color
None
# set pen color red using a hex value\
brain.screen.set_pen_color(0xFF0000)
# set pen color blue using predefined color\
brain.screen.set_pen_color(Color.BLUE)
# set pen color green using web string\
brain.screen.set_pen_color("#00FF00")
set_pen_width(width)
width : The pen width
None
x_position()
None
The X coordinate as an int
def foo():
print("screen pressed at ", brain.screen.x_position())
brain.screen.pressed(foo)
y_position()
None
The Y coordinate as an int
def foo():
print("screen pressed at ", brain.screen.y_position())
brain.screen.pressed(foo)
Sdcard
None
Instance of Sdcard class
appendfile(filename, *args)
Append is used to add more data to an existing file.
filename : The name of the file to write
buffer : A bytearray to write into the file
The number of bytes written
# append bytearray into file\
brain.sdcard.appendfile('MyTextFile.txt', bytearray("World "))
exists(*args)
filename : The name of the file to check
True if file exists
filesize(filename)
filename : The name of the file to check
size of file in bytes
is_inserted()
None
True if an sdcard is inserted into the brain
loadfile(filename, *args)
filename : The name of the file to read
buffer (optional) : A bytearray to read the file into
A bytearray with file data
# read file into new bytearray\
b = brain.sdcard.loadfile('MyTextFile.txt')
savefile(filename, *args)
If the optional bytearray is None, then an empty file is created.
filename : The name of the file to write
buffer (optional) : A bytearray to write into the file
The number of bytes written
# write bytearray into file\
brain.sdcard.savefile('MyTextFile.txt', bytearray("Hello "))
size(filename)
filename : The name of the file to check
size of file in bytes
The Brain.Lcd
class allows you to draw graphics, print text, and handle touch events on the V5 brain's screen.
vex.Brain.Lcd
A class used to access to screen on the V5 for drawing and receiving touch events.
None
An instance of the Brain.Lcd class
clear_row(number=None, color=Color.BLACK)
The color can be passed in similar ways to the Color class.\
row (optional) : The row to clear, default is current cursor row
color (optional) : The color the screen will be set to, default is BLACK
None
# clear row to black\
brain.screen.clear_row()
# clear row 2 to red\
brain.screen.clear_row(2, Color.RED)
clear_screen(color=Color.BLACK)
The color can be passed in similar ways to the Color class.\
color (optional) : The color the screen will be set to, default is BLACK
None
# clear screen to black\
brain.screen.clear_screen()
# clear screen to blue using predefined color\
brain.screen.clear_screen(Color.BLUE)
column()
Return the current column where text will be printed
draw_circle(x, y, radius, color=None)
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 height of the circle.
color (optional) : An optional fill color, the current fill color will be used if not supplied
None
# draw a green circle on the screen that is filled using blue\
brain.screen.set_pen_color(Color.GREEN)\
brain.screen.set_fill_color(Color.BLUE)\
brain.screen.draw_circle(50, 50, 10)
# draw a green circle on the screen that is filled using red\
brain.screen.set_pen_color(Color.GREEN)\
brain.screen.draw_circle(100, 50, 10, Color.RED)
draw_image_from_file(filename, x, y)
filename : The file name of the image.
x : The X coordinate for the top left corner of the image on the screen
y : The Y coordinate for the top left corner of the image on the screen
True if successfully drawn, False on error
# draw the vex.bmp image on the screen at coordinate 0, 0\
# an image named vex.bmp must be on the SD Card in the root folder\
brain.screen.draw_image_from_file('vex.bmp', 0, 0)
draw_line(x1, y1, x2, y2)
x1 : The x position of the beginning of the line referenced to the screen origin.
y1 : The y position of the beginning of the line referenced to the screen origin.
x2 : The x position of the end of the line referenced to the screen origin.
y2 : The y position of the end of the line referenced to the screen origin.
None
# draw a red line on the screen\
brain.screen.set_pen_color(Color.RED)\
brain.screen.draw_line(10, 10, 20, 20)
draw_pixel(x, y)
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.
None
# draw a red pixel on the screen\
brain.screen.set_pen_color(Color.RED)\
brain.screen.draw_pixel(10, 10)
draw_rectangle(x, y, width, height, color=None)
x : The x position of the rectangle top/left corner referenced to the screen origin.
y : The y position of the rectangle top/left corner referenced to the screen origin.
width : The width of the rectangle.
height : The height of the rectangle.
color (optional) : An optional fill color, the current fill color will be used if not supplied
None
# draw a green rectangle on the screen that is filled using blue\
brain.screen.set_pen_color(Color.GREEN)\
brain.screen.set_fill_color(Color.BLUE)\
brain.screen.draw_rectangle(10, 10, 20, 20)
# draw a green rectangle on the screen that is filled using red\
brain.screen.set_pen_color(Color.GREEN)\
brain.screen.draw_rectangle(50, 50, 20, 20, Color.RED)
get_string_height(*args)
arguments are in the same format as can be passed to the print function.
height of string as integer.
get_string_width(*args)
arguments are in the same format as can be passed to the print function.
width of string as integer.
next_row()
None
None
pressed(callback, arg=())
callback : A function that will be called when the screen is pressed
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("screen pressed")
brain.screen.pressed(foo)
pressing()
None
True or False
print(*args, **kwargs)
Optional keyword arguments:
sep : string inserted between values, default a space.
precision : the number of decimal places to display when printing simple numbers, default is 2
None
# print the number 1 on the screen at current cursor position\
brain.screen.print(1)
# print the numbers 1, 2, 3 and 4 on the screen at current cursor position separated by a '-'\
brain.screen.print(1, 2, 3, 4, sep='-')
# print motor1 velocity on the screen using a format string\
brain.screen.print("motor 1 : % 7.2f" %(motor1.velocity()))
print_at(*args, **kwargs)
Required keyword arguments
x : The x position of the text referenced to the screen origin.
y : The y position of the text referenced to the screen origin.
Optional keyword arguments:
sep : string inserted between values, default a space.
precision : the number of decimal places to display when printing simple numbers, default is 2
opaque : text does not clear background pixels if set to False. default is True.
None
# print the number 1 on the screen at position x=100, y=40\
brain.screen.print_at(1, x=100, y=40)
# print the numbers 1, 2, 3 and 4 on the screen at position x=100, y=40\
brain.screen.print_at(1, 2, 3, 4, x=100, y=40)
# print motor1 velocity on the screen using a format string at position x=100, y=40\
brain.screen.print_at("motor 1 : % 7.2f" %(motor1.velocity()), x=100, y=40)
released(callback, arg=())
callback : A function that will be called when the screen is released
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("screen released")
brain.screen.released(foo)
render()
Once called, further drawing will not appear on the screen until the next time\ render is called. This function will block until the screen can be updated.
None
True if buffer was successfully rendered to screen.
row()
Return the current row where text will be printed
set_clip_region(x, y, width, height)
All drawing is clipped to the given rectangle.\ This is set on a per thread basis.
x : The x position of the rectangle top/left corner referenced to the screen origin.
y : The y position of the rectangle top/left corner referenced to the screen origin.
width : The width of the rectangle.
height : The height of the rectangle.
None
set_cursor(row, col)
row and column spacing will take into account the selected font.\ The base cell size if 10x20 pixels for the MONO20 font.\ text may not accurately print if using a proportional font.\ The top, left corner of the screen is position 1,1
row : The cursor row
col : The cursor column
None
set_fill_color(color)
The color can be passed in similar ways to the Color class.\ The color is specific to the running thread.
color : The fill color
None
# set pen color red using a hex value\
brain.screen.set_fill_color(0xFF0000)
# set pen color blue using predefined color\
brain.screen.set_fill_color(Color.BLUE)
# set pen color green using web string\
brain.screen.set_fill_color("#00FF00")
set_font(fontname)
fontname : The font name
None
brain.screen.font_type(FontType.MONO40)
set_origin(x, y)
drawing functions consider the top left corner of the screen as the origin.\ This function can move the origin to an alternate position such as the center of the screen.
x : The origins x position relative to top left corner
y : The origins y position relative to top left corner
None
set_pen_color(color)
The color can be passed in similar ways to the Color class.\ The color is specific to the running thread.
color : The pen color
None
# set pen color red using a hex value\
brain.screen.set_pen_color(0xFF0000)
# set pen color blue using predefined color\
brain.screen.set_pen_color(Color.BLUE)
# set pen color green using web string\
brain.screen.set_pen_color("#00FF00")
set_pen_width(width)
width : The pen width
None
x_position()
None
The X coordinate as an int
def foo():
print("screen pressed at ", brain.screen.x_position())
brain.screen.pressed(foo)
y_position()
None
The Y coordinate as an int
def foo():
print("screen pressed at ", brain.screen.y_position())
brain.screen.pressed(foo)
The Brain.Battery
class provides information about the V5 brain's battery, such as capacity, voltage, current, and temperature.
vex.Brain.Battery
None
Instance of Battery class
capacity()
None
capacity as percentage
current(units=CurrentUnits.AMP)
units (optional) : AMP, default is mA but jot available as an enum.
current in supplied units
temperature(units=PercentUnits.PERCENT)
units (optional) : PERCENT, CELSIUS or FAHRENHEIT, default is CELSIUS
temperature in supplied units
voltage(units=VoltageUnits.MV)
units (optional) : VOLTS or MV, default is MV
voltage in supplied units
The Brain.Sdcard
class allows you to interact with the SD card inserted into the V5 brain, including file operations.
vex.Brain.Sdcard
None
Instance of Sdcard class
appendfile(filename, *args)
Append is used to add more data to an existing file.
filename : The name of the file to write
buffer : A bytearray to write into the file
The number of bytes written
# append bytearray into file\
brain.sdcard.appendfile('MyTextFile.txt', bytearray("World "))
exists(*args)
filename : The name of the file to check
True if file exists
filesize(filename)
filename : The name of the file to check
size of file in bytes
is_inserted()
None
True if an sdcard is inserted into the brain
loadfile(filename, *args)
filename : The name of the file to read
buffer (optional) : A bytearray to read the file into
A bytearray with file data
# read file into new bytearray\
b = brain.sdcard.loadfile('MyTextFile.txt')
savefile(filename, *args)
If the optional bytearray is None, then an empty file is created.
filename : The name of the file to write
buffer (optional) : A bytearray to write into the file
The number of bytes written
# write bytearray into file\
brain.sdcard.savefile('MyTextFile.txt', bytearray("Hello "))
size(filename)
filename : The name of the file to check
size of file in bytes