import lejos.nxt.*;
import lejos.navigation.Pilot;
@author
public class SquareTracer2
{
Pilot pilot ;
public void drawSquare(float length)
{
byte direction = 1;
if(length < 0 )
{
direction = -1;
length = -length;
}
for(int i = 0; i<4 ; i++)
{
pilot.travel(length);
pilot.rotate(direction * 90);
}
}
public static void main( String[] args)
{
System.out.println(" Square Tracer 2");
Button.waitForPress();
SquareTracer2 sq = new SquareTracer2();
sq.pilot = new Pilot(2.25f, 5.5f, Motor.A, Motor.C);
byte direction = 1;
int length = 20;
for(int i = 0; i<4; i++)
{
sq.drawSquare(direction * length );
if( i == 1)
{
sq.pilot.rotate( 90);
direction = -1;
}
}
}
}