I'm using lejos version 9.0 beta, and nxt 2.0.
I want to use a Listener for the LightSensor but it doesn't work
The LightListener is never called and the light of the LightSensor isn't even turned on.
But if I use a Listener for the TouchSensor there are no Problems. What is wrong on my exampel program???
- Code: Select all
import lejos.nxt.*;
public class TestProgramm {
public static void main(String[] args){
TestProgramm a = new TestProgramm ();
a.go();
}
public void go (){
MyLightListener lightListener = new MyLightListener ();
MyTouchListener touchListener = new MyTouchListener ();
LightSensor light = new LightSensor (SensorPort.S1);
TouchSensor touch = new TouchSensor (SensorPort.S2);
SensorPort.S1.addSensorPortListener(lightListener);
SensorPort.S2.addSensorPortListener(touchListener);
LCD.drawString("LightListener:", 0, 1);
LCD.drawString("TouchListener:", 0, 4);
Button.waitForPress();
}
class MyLightListener implements SensorPortListener {
public void stateChanged(SensorPort source, int oldValue, int newValue) {
LCD.drawString("alt: "+ oldValue + " neu: " + newValue, 0, 2);
}
}
class MyTouchListener implements SensorPortListener {
public void stateChanged (SensorPort source, int oldValue, int newValue){
LCD.drawString("alt: " + oldValue + " neu: " + newValue, 0, 5);
}
}
}
