Vex CORTEX Manual de instrucciones Pagina 55

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 166
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 54
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
Vista de pagina 54
1 2 ... 50 51 52 53 54 55 56 57 58 59 60 ... 165 166

Comentarios a estos manuales

Sin comentarios