- Code: Select all
while (!Button.ESCAPE.isPressed()){
i = sonic.getDistance();
if (i < 38){
Motor.A.setSpeed(3000f);
Motor.B.setSpeed(3000f);
Motor.A.backward();
Motor.B.backward();
Thread.sleep(800);
Motor.A.setSpeed(3000f);
Motor.B.setSpeed(1500f);
Motor.A.backward();
Motor.B.backward();
Thread.sleep(700);
Motor.B.setSpeed(3000f);
Motor.A.forward();
Motor.B.forward();
}
}
}
NOTE: The sensor is defined outside the loop and is working properly, I know there is no delay in the sensor. Also, as of right now the code is working, but not the way I want it to. I had to slow down the NXT and increase the distance of detection from 8cm to 38cm to avoid hitting the wall
