import lejos.nxt.*; import lejos.robotics.navigation.*; /** * travel in a square path * * @author www.lejos.org - Roger * @author adapted by Sharon Tuttle * @version 2015-02-17 */ public class SquareTracer { // data field private DifferentialPilot pilot; /** * travel in a square path, where each side of the * square is a given length * * param sideLength length of a side of the square path to * travel */ public void drawSquare(float sideLength) { for(int i=0; i<4; i++) { pilot.travel(sideLength); pilot.rotate(90); } } /** * create a pilot and have it travel a square path * * @param args not used */ public static void main(String[] args) { SquareTracer sqTracer = new SquareTracer(); sqTracer.pilot = new DifferentialPilot(56f, 120f, Motor.B, Motor.C); System.out.println("Press Button"); Button.waitForAnyPress(); for (int i=0; i<5; i++) { LCD.clear(); sqTracer.drawSquare(100 * i); System.out.println("Press Button"); Button.waitForAnyPress(); } } }