task main() { //Program begins, insert code within curly braces untilSonarLessThan(20, sonar); //waits for the sonar sensor todetect an object within 20cm startMotor(leftMotor, 63); //turns on left motor startMotor(rightMotor, 63); //turns on right motor untilSonarGreaterThan(25, sonar); //waits for the object to move to a distance greater than 25cm stopMotor(leftMotor); //Stops left motor stopMotor(rightMotor); //Stops right motor }
task main() { robotType(recbot); // We are using the recbot. wait(2.0); // Wait 2.0 seconds to initialize the sonar sensor and position robot. forward(63); // Move forward at speed 63. untilSonarLessThan(20); // Wait until the sonar sees an object 20cm away. (in default sonar ports) stop(); // Stop. }
task main() { forward(75); // move forward at speed 75 untilSonarLessThan(40); // continue until the sonar reads a value less than 40 stop(); // stop the robot }