• Moving back and forth

    This simple program allows your robot to go forward a specific distance and then go backward and return to it’s starting spot.  You program your robot to go a specific number of degrees and then you know exactly how far it will

    task main()

    {                                          
    //Reset the motorEncoders                
                 SensorValue(rightEncoder) = 0;           
                 SensorValue(leftEncoder) = 0;                
                 wait1Msec(100);  //short pause to reduce jerky motor movement
                                                   

    //set the encoder target
    //for 5 rotations, we want to rotate 5 * 1800 degrees

                while(SensorValue[rightEncoder] < 1800)
    {                             
    //start both motors at half speed
                 startMotor(rightMotor, 63);
                 startMotor(leftMotor, 63);
    }

    //stop both motors
    stopMotor(rightMotor);
    stopMotor(leftMotor);
    wait1Msec(2000);  //pause for 2 seconds
    {

    //reset both motor Encoders to zero
    SensorValue(rightEncoder) = 0;
    SensorValue(leftEncoder) = 0;
    wait1Msec(100); //pause .5 second to reduce jerky motor movement

    //for 5 rotations, we want to rotate 5 * 1800 degrees
    while(SensorValue(rightEncoder) > -1800)
    {
    startMotor(rightMotor, -60);
    startMotor(leftMotor, -60);
    }
    {
    //stop both motors
    stopMotor(rightMotor);
    stopMotor(leftMotor);
    }
    }
    }