Consola de impresión#
Los comandos de la consola de impresión solo están disponibles al usar VEXcode EXP. Si está programando en VS Code, deberá imprimir en la pantalla cerebral de EXP usando los comandos Brain.Screen
.
Todos los proyectos nuevos comienzan con el cursor en la fila 1 de la Consola de impresión.
Comandos#
Print to the Print Console#
The printf(text)
method prints text on the screen using the current cursor position.
Parámetros |
Descripción |
---|---|
texto |
La cadena (entre comillas) o números enteros que se imprimirán en la Consola de impresión. |
Formato#
Los valores que se imprimen en la consola de impresión pueden usar especificadores de formato para mostrar valores dentro de sus declaraciones de impresión.
%d
- Decimal Integer%f
- Decimal Floating Point Number%o
- Signed Octal%s
- String of Characters%x
- Unsigned Hexadecimal Integer%c
- Character
Este ejemplo imprimirá la hora actual del cerebro V5 como un número de punto flotante con 2 decimales.
printf("Screen Pressed? %s\n", Brain.Screen.pressing());
Los especificadores de formato también pueden contener indicadores para modificarlos aún más:
%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.
Nuevas líneas#
/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");
Diferentes colores#
Puede cambiar el color del texto al imprimir en la Consola de impresión utilizando los siguientes códigos de color:
[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");
Devoluciones: Ninguna.
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.
El siguiente ejemplo imprimirá “VEXcode” y luego borrará la consola de impresión después de 2 segundos.
printf("VEXcode\n");
wait(2, seconds);
printf("\033[2J\n");