Programming instructions

Reference
Project Lead The Way
©
and Carnegie Mellon Robotics Academy
©
/ For use with VEX
®
Robotics Systems
Reserved Words 5
Reserved Words
srand(16); //Assign 16 as the value of the seed
random(100); //Generates a number between 0 and 100
while(time1[T1]<5000)//While the timer is less than 5 sec...
{
motor[port3]= 127;//...motor port3 runs at 100%
}
if(sensorValue(bumper) ==1)//the bumper is used as...
{ //...the condition
motor[port3]= 0; //if it’s pressed port3 stops
}
else
{
motor[port3]= 127; //if it’s not pressed port3 runs
}
Miscellaneous
Miscellaneous useful commands that are not part of the standard C language.
srand(seed);
Denes the integer value of the “seed” used in the random() command to generate a random
number. This command is optional when using the random() command, and will cause the same
sequence of numbers to be generated each time that the program is run.
random(value);
Generates random number between 0 and the number specied in its parenthesis.
Control Structures
Program control structures in ROBOTC enable a program to control its ow outside of the typical
top to bottom fashion.
task main(){}
Creates a task called “main” needed in every program. Task main is responsible for holding the
code to be executed within a program.
while(condition){}
Used to repeat a {section of code} while a certain (condition) remains true. An innite while loop
can be created by ensuring that the condition is always true, e.g. “1==1” or “true”.
if(condition){}/else{}
With this command, the program will check the (condition) within the if statement’s parentheses
and then execute one of two sets of code. If the (condition) is true, the code inside the if state-
ment’s curly braces will be run. If the (condition) is false, the code inside the else statement’s curly
braces will be run instead. The else condition is not required when using an if statement.
Go to Reference Links