Programming instructions

Reference
Project Lead The Way
©
and Carnegie Mellon Robotics Academy
©
/ For use with VEX
®
Robotics Systems
Main Title 2
#pragma cong(Sensor, dgtl1, Estop, sensorTouch)
#pragma cong(Sensor, dgtl2, controlBtn, sensorTouch)
#pragma cong(Sensor, dgtl3, LED, sensorDigitalOut)
task main()
{
while(SensorValue[Estop] == 0)
{
if(SensorValue[controlBtn] == 1)
{
turnLEDOn(LED);
}
else
{
turnLEDOff(LED);
}
}
}
Checks if count is “less than” 4.
task main()
{
int count = 0;
while(count < 4)
{
startMotor(port2, 63);
wait(5.0);
startMotor(port2, -63);
wait(5.0);
count = count + 1;
}
}
Below is an example of a program using a counter-controlled While Loop.
Creates an integer variable named
“count” and gives it an initial value of 0.
Adds 1 to count every time the loop runs.
Result: The loop repeats 4 times, caus-
ing the port2 motor to turn back and
forth, four times.
Checks if the “Estop” touch sensor
is equal to 0 (unpressed).
Below is an example of a program using a sensor-controlled While Loop.
If the “controlBtn” is pressed, turn the
LED on; if it’s not, turn the LED off.
Result: The loop repeats continuously,
allowing the LED to be turned on while
the “controlBtn” is pressed, and off while
“controlBtn” is released. The loop will
stop as soon as the “Estop” touch sensor
is pressed.
While Loops with Natural Language
Go to Reference Links