// DriveWTListen.java // // A program to illustrate the use of the NXT Motors, extended // with a Listener on a touch sensor // // Simon Parsons // 22nd October 2013 import lejos.nxt.Button; import lejos.nxt.LCD; import lejos.nxt.Motor; import lejos.nxt.SensorPort; import lejos.nxt.TouchSensor; public class DriveWTListen{ public static void main(String[] args){ // This is the touch sensor we will use TouchSensor leftBump = new TouchSensor(SensorPort.S2); // The listener goes on the sensor port SensorPort.S2.addSensorPortListener(new LTouchListener()); System.out.println("Press any button to start robot"); Button.waitForAnyPress(); LCD.clear(); System.out.println("Press the left bumper to stop robot"); Motor.B.forward(); Motor.C.forward(); try{ Thread.sleep(10000);} catch(Exception e){ // Nothing } } }