|Use:||print( value1, value2, … )|
|Description:||Prints text onto the mpyEditor console window.|
|Values to printed.Value may be a variable, a number, or a string. Any number of values may be used|
The print function writes text in Green onto the mpyEditor window. The Launchpad board must be connected to the PC, and the Launchpad driver must be installed (see here for instructions).
The print function uses the UART pin P1_1 this pin is connected through the USB interface so that it can send messages back to the PC. If you want to use the print function you must make sure you do not use pin P1_1 for something else, otherwise the print function may not work. Also to see the first print lines you should press the Launchpad RESET button.
The printed value can be a variable, a number, or text.
A text value must be surrounded in single or double quotes, (Note text cannot be assigned to a variable.)
print( 'The program has started' ) pindir(P1_0,OUT) out(P1_0, 1) print( 'The RED Led is ON' )
When the program runs you should see the following lines printed out on the mpyEditor
The program has started The RED Led is ON
You can use the print statement to print multiple values, and each value must be separated by a ‘,’.
x = 200 print( 'The value of x is ', x, ' in decimal' )
This will print the following in the mpyUart window
The value of x is 200 in decimal
Each print statement is printed out on a new line. However if the there is no parameter after the last ‘ , ‘ this will cause the next print command to print out on the same line, for example:
print( 'Oh no! There is a Creeper ' , ) print( 'sssss BOOM')
Oh No! There is a Creeper sssss BOOM
If the variable name ends with ‘_hex‘, the variable will be printed using hexadecimal format. Hexadecimal numbers are often useful when you are using hardware registers in the microcontroller. For example
y_hex = 1000 print( 'The hexadecimal value of y_hex is ', y_hex )
The hexadecimal value of y_hex is 3E8
Note: Variable names which end with ‘_hex‘ are just the same as ordinary variables. The ‘_hex‘ just changes the way it gets displayed with the print command.