0

Soccer Robot C - Basic lessons - Print

The robot is able to communicate with the operator using USB cable or radio link (Bluetooth or WiFi). The purpose is to show robot's status, feedback, etc. Command that is used is print. Its format is not simple. In this stage, we will not be exploring all the options but will just show You how to print simple messages (strings). This simplified syntax is easy: print("message");. message is some text. For example
	print("Hello, user!");
will print the text in quotes, "Hello, user!" in the monitor of Your PC. The whole function is here:
void RobotSoccer::loop() {
	print("Hello, user!");
	end();
}
The function ends with command end(). Without it, the printing would continue forever. Try the program.
Now try a program like this:
void RobotSoccer::loop() {
	print("Hello, user!");
	print("Goodbye, user!");
	end();
}
The result will be: "Hello, user!Goodbye, user!". We expected the program to print 2 lines, one below another, but the both messages are printed together in the same line. How to correct this? Now comes an uglier part of C/C++, special characters. To jump to a new line, You will have to use 2 of them:
  • \n
  • \r
The first one, \n, means "new line", jump to a new line. The second "carriage return", start printing from the beginning of the line. When the signs were invented, mechanical typewriters were in fashion, therefore "carriage" was used. The whole program is here:
void RobotSoccer::loop() {
	print("Hello, user!\n\r");
	print("Goodbye, user!");
	end();
}
Remember to end any string, after which You need to print in the next line, with "\n\r".

Task: print a message

Write a program that will print "1", "2", and "3" in 3 different lines.