I have worked with the RCX brick, and to set up a listener, the type and mode need to be specified. However with the NXT, i don't know what type and mode to use for the UltraSonic sensor. With the RCX the sensors and modes were constants, and there are constants with the NXT, but i don't think any of those will work for the UltraSonic sensor. I do understand that the UltraSonic sensor is a I2C sensor, but i don't know what to put in the SensorPort.S1.setTypeAndMode(??,??), or even if it can be done this way... Here is the code that i would like to run:
- Code: Select all
import lejos.nxt.*;
public class SonicTest {
public static void main(String[] args) throws Exception
{
// Initialize the sensors
SensorPort.S1.setTypeAndMode(<TYPE>, <MODE>);
// Initialize the listener
SonicListener listener = new SonicListener();
SensorPort.S1.addSensorPortListener(listener);
Button.ESCAPE.waitForPressAndRelease();
}
public static class SonicListener implements SensorPortListener
{
public void stateChanged(SensorPort source, int oldValue, int newValue)
{
Sound.playTone(50,10);
LCD.clear();
LCD.drawInt(newValue, 0, 0);
LCD.refresh();
}
}
}