I've been struggling for some time on this. I'm trying to code the robot to move when the distance is above a certain integer and stop when the distance becomes lower than the certain integer. I'm coding in Eclipse Helios. My code is below:
import lejos.nxt.Button;
import lejos.nxt.Motor;
import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;
public class robot {
public static void main(String[] args) {
UltrasonicSensor us1 = new UltrasonicSensor(SensorPort.S4);
System.out.print(us1.getDistance());
if (us1.getDistance() >= 25);
Motor.A.setSpeed(50);
Motor.C.setSpeed(50);
Motor.A.forward();
Motor.C.forward();
if (us1.getDistance() < 25);
Motor.A.backward();
Motor.C.backward();
Button.waitForAnyPress();
}
}