Programming instructions

Reference
Project Lead The Way
©
and Carnegie Mellon Robotics Academy
©
/ For use with VEX
®
Robotics Systems
Comments 1
#pragma cong(Sensor, dgtl1, bumper, sensorTouch)
#pragma cong(Motor, port2, armMotor, tmotorNormal, openLoop)
//*!!Code automatically generated by ‘ROBOTC’!!*//
/*
This is part of a multi-line comment.
This program uses commenting to describe each process.
*/
task main()
{
startMotor(armMotor, 63); //Turn armMotor on at 1/2 power
untilTouch(bumper); //Wait for bumper switch to be touched
stopMotor(armMotor); //Stop the armMotor
}
Below is an example of a program with single and multi-line comments. Commented text turns green.
Commenting a program means using descriptive text to explain portions of code. The
compiler and robot both ignore comments when running the program, allowing a programmer
to leave important notes in non-code format, right alongside the program code itself. This is
considered very good programming style, because it cuts down on potential confusion later
on when someone else (or even you) may need to read the code.
There are two ways to mark a section of text as a comment rather than normal code:
Type Start Notation End Notation
Single line // (none)
Multiple line /* */
“Commenting out” Code
Commenting is also sometimes used to temporarily “disable” code in a program without
actually deleting it. In the program below, the programmer has code to move an arm up and
then move the arm down. However, in order to test only the second half of the program, the
programmer made the rst behavior into a comment, so the robot will ignore it. When the
programmer is done testing the second behavior, he/she can remove the // comment marks to
re-enable the rst behavior in the program.
task main()
{
//startMotor(armMotor, 63); //Turn armMotor on at 1/2 power
//untilTouch(bumper); //Wait for bumper switch to be touched
//stopMotor(armMotor); //Stop the armMotor
wait(2.0); //Wait 2.0 seconds
startMotor(armMotor, -63); //Turn armMotor on at -1/2 power
untilRelease(bumper); //Wait for bumper switch to be released
stopMotor(armMotor); //Stop the armMotor
}
Comments with Natural Language
Go to Reference Links