Anyway, the following is the first piece of Java code I've ever written and had work. It returns a current sensor reading and displays it on the LCD. This code also updates the value on screen to the current sensor reading for every iteration through the 'for' statement.
I should mention I've only tested this with the LightSensor but I don't see why it wouldn't work with the others.
Check it out,
- Code: Select all
import lejos.nxt.LCD;
import lejos.nxt.LightSensor;
import lejos.nxt.SensorPort;
public class HelloWorld {
public static void main(String[] args) {
LightSensor ls;
int t;
ls = new LightSensor(SensorPort.S2, true);
for(int i = 0; i<10000; i++) {
t = ls.readNormalizedValue();
LCD.drawInt(t,0,0);
LCD.refresh();
}
}
}
Let me know what you think. Any advice is appreciated advice.
//Matt

