import lejos.nxt.Button;
import lejos.nxt.Motor;
import lejos.nxt.SensorPort;
import lejos.nxt.TouchSensor;
import lejos.robotics.navigation.DifferentialPilot;
import lejos.util.Delay;
public class ProvaTouch {
public static void main(String[] args) {
TouchSensor ts = new TouchSensor(SensorPort.S4);
DifferentialPilot dp = new DifferentialPilot(5.5, 11.5, Motor.A, Motor.C);
dp.forward();
do {
if (ts.isPressed()) {
dp.backward();
Delay.msDelay(500);
dp.rotate(180);
dp.forward();
}
} while (!Button.ESCAPE.isDown());
dp.stop();
}
}
Giorno: 1 Marzo 2016
Disegno per NXT classe 3E
Realizzare il disegno seguente; i rettangoli devono avere coordinate (0,0) – (4,4) – (8,8) – etc.

import javax.microedition.lcdui.Graphics;
import lejos.nxt.Button;
public class Disegna {
public static void main(String[] args) {
Graphics g = new Graphics();
int w = g.getWidth() - 1;
int h = g.getHeight() - 1;
for (int x = 0; x < h; x += 4) {
// lato orizzontale superiore
g.drawLine(x, x, w - x, x);
// lato orizzontale inferiore
g.drawLine(x, h - x, w - x, h - x);
// lato verticale sinistro
g.drawLine(x, x, x, h - x);
// lato verticale destro
g.drawLine(w - x, x, w - x, h - x);
}
Button.ESCAPE.waitForPressAndRelease();
}
}