Programming instructions

Reference
Project Lead The Way
©
and Carnegie Mellon Robotics Academy
©
/ For use with VEX
®
Robotics Systems
Functions 2
void rotateArm(oat time)
{
startMotor(armMotor,63);
wait(time);
stopMotor(armMotor);
}
task main()
{
rotateArm(3.25);
}
void rotateArm(oat time)
{
startMotor(armMotor,63);
wait(time);
stopMotor(armMotor);
}
task main()
{
rotateArm(3.25);
}
Advanced Functions
Parameters
Parameters are a way of passing information into a function, allowing the function to run its
commands differently, depending on the values it is given. It may help to think of the parameters
as placeholders – all parameters must be lled in with real values when the function is called, so
in the places where a parameter appears, it will simply be replaced by its given value.
1. Declare parameter
A parameter is declared in the same way
that a variable is (type then name) inside the
parentheses following the function name.
2. Use parameter
The parameter value behaves like a
“placeholder”. Whatever value is provided
for the parameter when the function is called
will appear here.
3. Call function with parameter
When the function is called, a value must be
provided within the parentheses to take the
place of the parameter inside the function.
startMotor(armMotor,63);
wait(3.25);
stopMotor(armMotor);
Substitution
The arrows in the illustration to the right show
the general “path” of the value from the place
where it is provided in the function call, to
where its value is substituted into the function.
The function will run as if the code read as it
does in the bottom box.
Go to Reference Links