void rightTurn()
{
int threshold = 7;
while(SensorValue(sonarSensor) > threshold || SensorValue(sonarSensor) == -1) // while the sonarSensor sensor is reading in values larger than our
{ // threshold, or reading out of range (-1 = no object in sight)
// move forward:
motor[rightMotor] = -75; // set port2 to speed 75
motor[leftMotor] = 75; // set port3 to speed 75
}
stopAllMotors(); // stop the robot:
motor[rightMotor] = 0; // set port2 to speed 0
motor[leftMotor] = 0; // set port3 to speed 0
motor[rightMotor] = 25;
motor[leftMotor] = 25;
wait1Msec(1000);
stopAllMotors();
motor[rightMotor] = 5;
motor[leftMotor] = 5;
wait1Msec(300);
}
void leftTurn()
{
int threshold = 7; // create and set variable 'threshold' to 7 (will be distance for sonarSensor)
while(SensorValue(sonarSensor) > threshold || SensorValue(sonarSensor) == -1) // while the sonarSensor sensor is reading in values larger than our
{ // threshold, or reading out of range (-1 = no object in sight)
// move forward:
motor[rightMotor] = -75; // set port2 to speed 75
motor[leftMotor] = 75; // set port3 to speed 75
}
stopAllMotors(); // stop the robot:
motor[rightMotor] = 0; // set port2 to speed 0
motor[leftMotor] = 0; // set port3 to speed 0
motor[rightMotor] = -25;
motor[leftMotor] = -25;
wait1Msec(1000);
//Brief brake to stop some drift
motor[rightMotor] = 5;
motor[leftMotor] = 5;
wait1Msec(300);
}
void finish()
{
// Robot waits for 2000 milliseconds before executing program
while(SensorValue[in4] < 1500) // While the ambient lightSensor reads a value less than 200
{
motor[rightMotor] = -63; // Motor on port2 is run at half (63) power forward
motor[leftMotor] = 63; // Motor on port3 is run at half (63) power forward
wait1Msec(1500); // Robot runs previous code for 1500 milliseconds before moving on
}
}
task main()
{
rightTurn();
leftTurn();
repeat(3)
{
rightTurn();
}
repeat(4)
{
leftTurn();
}
repeat(4)
{
rightTurn();
}
repeat(2)
{
leftTurn();
}
finish();
}