Braitenberg1.java
import lejos.nxt.Button;
import lejos.nxt.ButtonListener;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.LightSensor;
 
/**
 * The locomotions of a LEGO 9797 car is controlled by sound detected through a
 * microphone on port 1.
 * 
 * @author Ole Caprani
 * @version 23.08.07
 */
public class Braitenberg1 implements ButtonListener {
    private static LightSensor sensor = new LightSensor(SensorPort.S1, false);
 
    private static boolean running;
 
    public Braitenberg1() {
        Button.ESCAPE.addButtonListener(this);
    }
 
    public static void main(String[] args) throws Exception {
        Braitenberg1 pf = new Braitenberg1();
        running = true;
        LCD.drawString("dB level: ", 0, 0);
        LCD.refresh();
 
        while (running) {
            int light = sensor.getLightValue();
 
            Car.forward(light, light);
 
            LCD.drawString("Light:  " + light, 0, 0);
 
            Thread.sleep(50);
        }
        Car.stop();
        LCD.clear();
        LCD.drawString("Program stopped", 0, 0);
        Thread.sleep(2000);
    }
 
    @Override
    public void buttonPressed(Button arg0) {
    }
 
    @Override
    public void buttonReleased(Button arg0) {
        running = false;
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License