I have developed a class to control this hardware.
How to test this sensor?
- Code: Select all
package lejos.nxt;
//http://www.techno-stuff.com/Nmotion.htm
//Motion Sensor for NXT
public class MotionSensor implements SensorConstants
{
ADSensorPort port;
private int _zero = 1023;
private int _hundred = 0;
public MotionSensor(ADSensorPort port)
{
this.port = port;
port.setTypeAndMode(TYPE_LIGHT_ACTIVE,
MODE_PCTFULLSCALE);
}
public int readValue()
{
return port.readRawValue();
}
}
- Code: Select all
import lejos.nxt.*;
public class MotionTest {
public static void main(String[] args) throws Exception {
MotionSensor msObj = new MotionSensor(SensorPort.S1);
while(!Button.ESCAPE.isPressed()) {
LCD.clear();
LCD.drawInt(msObj.readValue(), 0, 0);
LCD.refresh();
Thread.sleep(500);
}
}
}

