打印控制台#
打印控制台命令仅在使用 VEXcode EXP 时可用。如果您在 VS Code 中编码,则需要使用 Brain.Screen
命令打印到 EXP 的 Brain Screen。
所有新项目都从打印控制台中的第 1 行光标开始。
命令#
Print to the Print Console#
The printf(text)
method prints text on the screen using the current cursor position.
参数 |
描述 |
---|---|
文本 |
要打印到打印控制台的字符串(在引号中)或整数。 |
格式#
打印到打印控制台的值可以使用格式说明符来显示打印语句内的值。
%d
- Decimal Integer%f
- Decimal Floating Point Number%o
- Signed Octal%s
- String of Characters%x
- Unsigned Hexadecimal Integer%c
- Character
此示例将 V5 Brain 的当前时间打印为具有 2 位小数的浮点数。
printf("Screen Pressed? %s\n", Brain.Screen.pressing());
格式说明符还可以包含标志以进一步修改它们:
%6f
- This prints a floating point number that is a minimum of 6 characters wide.%.2f
- This prints a floating point number with 2 decimal places.%6.2f
- This prints a floating point number that is a minimum of 6 characters wide with 2 decimal places.
新线#
/n
is a newline character, and it is required by the printf
command to output any of its contents to the Print Console.
printf("This text will be ");
printf("printed on the same line\n");
printf("This is on a new line\n");
不同的颜色#
您可以使用以下颜色代码更改打印到打印控制台时文本的颜色:
[31m
- Red[32m
- Green[34m
- Blue[30m
- Black[37m
- White[33m
- Yellow[91m
- Orange[35m
- Purple[36m
- Cyan[97m
- Transparent
All color codes need to be attached to an escape sequence = \033
in order to function.
You can either use this directly in a print
command with a string.
// Print VEXcode in Red to the Print Console.
printf("\033[31m VEXcode\n");
Or, you can use it on its own to set all print
commands afterwards to the set color.
// Set the Print Console text color to Red before printing VEXcode.
printf("\033[31m");
printf("VEXcode\n");
**返回:**无。
Clear the Print Console#
By using \033[2J\n
inside of the printf
command, you can clear the entire Print Console. This will also set the cursor back to row 1.
下面的示例将打印“VEXcode”,然后在 2 秒后清除打印控制台。
printf("VEXcode\n");
wait(2, seconds);
printf("\033[2J\n");