Console#
Introduction#
The VEXcode IQ (2nd gen) Console is displayed in the Monitor window within VEXcode. Console output can display text, numbers, and variable values while a project is running.
When using VS Code, text-based Console output appears in the terminal instead of the VEXcode Console.
Note: When using the VEXcode Console, you must connect to the Console Serial Port before any output can be printed to the Console.
Below is a list of all functions:
Action — Output text.
printf— Displays text, numbers, or variable values in the Console or terminal.
Action#
printf#
printf displays text, numbers, or variable values in the Console. In VS Code, printf displays output in the terminal.
In C++, printf uses a format string. The format string is the text inside the quotation marks. It can include regular text, control sequences, and format specifiers that insert values from your project, like a score, timer, or sensor reading. See the String Formatting page for more information about format specifiers.
By default, printf does not automatically move to the next line. Add \n, which stands for a new line, when you want the next printed value to start on a new row.
Usage:
printf(value);
Parameter |
Type |
Description |
|---|---|---|
|
|
The text, format string, or control sequence to display in the Console or terminal. |
Return Value:
This function does not return a value.
// Display a message in the Console
printf("Hello, robot!\n");

// Display two messages on separate lines
printf("Hello, robot!\n");
printf("This prints on the next line.\n");

// Display two messages on the same line
printf("Hello, ");
printf("robot!\n");

// Display a number with two decimal places
printf("%.2f\n", 1.0 / 3.0);

Control Sequences#
Control sequences are short codes that can be printed with printf to change how text appears in the Console.
Control sequences are useful when you want to change text color or clear the Console directly inside a printf statement.
To change the text color, print \033 followed by a color code. At the start of a project, the Console text color is set to blue.
Color |
Control sequence |
|---|---|
Black |
|
Red |
|
Green |
|
Yellow |
|
Blue |
|
Purple |
|
Cyan |
|
White |
|
Orange |
|
// Print text in different colors
printf("Default text color\n");
printf("\033[31m");
printf("Red text color\n");

Clear the Console#
C++ does not have a separate Console function for clearing all rows. To clear the Console, print the control sequence \033[2J with printf.
This clears all rows from the Console and moves the cursor back to row 1.
// Clear the Console after two seconds
printf("VEXcode\n");
wait(2, seconds);
printf("\033[2J");