import tinyvm.rcx.*; public class SmallCar{ static Object[] iDevices = new Object[] { Sensor.S1, Sensor.S2, Sensor.S3, Motor.A, Motor.B, Motor.C }; static int behaviour=0; static int currentBehaviour=0; public static void main(String[] args){ Sensor.S1.addSensorListener(new SensorListener(){ public void stateChanged(Sensor aSource, int value){ if(value<1010){ behaviour=1; LCD.showProgramNumber(1); } } public void stateChanged(Sensor aSource, boolean state){} } ); Sensor.S2.addSensorListener(new SensorListener(){ public void stateChanged(Sensor aSource, int value){ if(value<1010){ behaviour=2; LCD.showProgramNumber(2); } } public void stateChanged(Sensor aSource, boolean state){} } ); Sensor.S3.addSensorListener(new SensorListener(){ public void stateChanged(Sensor aSource, int value){ if(value<1010){ behaviour=3; LCD.showProgramNumber(3); } } public void stateChanged(Sensor aSource, boolean state){} } ); while(true){ currentBehaviour=behaviour; if(currentBehaviour==1){//avoid left Motor.A.setPower(7); Motor.A.forward(); Motor.C.stop(); Time.sleep(100); Motor.C.setPower(2); Motor.C.forward(); behaviour=0; Time.sleep(2000); } else if(currentBehaviour==2){//avoid front Motor.A.setPower(5); Motor.C.setPower(5); Motor.A.backward(); Motor.C.backward(); behaviour=0; Time.sleep(2000); } else if(currentBehaviour==3){//avoid right Motor.C.setPower(7); Motor.C.forward(); Motor.A.stop(); Time.sleep(100); Motor.A.setPower(2); Motor.A.forward(); behaviour=0; Time.sleep(2000); } else{//rest Motor.A.flt(); Motor.C.flt(); } } } }