import lejos.nxt.*; import lejos.util.*; /** play with rotation control @author Roger (from a www.lejos.org tutorial) @author extensively modified by Sharon Tuttle @version 2015-02-06 **/ public class RotatePlay { /** try calling rotate and rotateTo in both their 1 and 2 argument versions @param args not used **/ public static void main(String[] args) { System.out.println("rotate play"); Button.waitForAnyPress(); LCD.clear(); // rotate the motor 4 completed revolutions // (360 * 4), and this call will return // WHEN that rotation is complete -- // try to observe WHEN the BURP appears // on-screen -- it should be AFTER the // 4 revolutions are complete Motor.B.rotate(1440); LCD.drawString("DELAYED BURP!", 0, 0); LCD.drawString("near 1440? " + Motor.B.getTachoCount(), 0, 1); Button.waitForAnyPress(); // I want to go 1440 degree of rotation MORE, // BUT I'm going use a 2nd argument of true // -- you'll see the BURP here BEFORE the // additional rotations are done Motor.B.rotate(1440, true); LCD.drawString("NOT-DELAYED BURP!", 0, 2); // idea: please WAIT to press button until // rotations stop... Button.waitForAnyPress(); LCD.drawString("near 2880? " + Motor.B.getTachoCount(), 0, 3); Button.waitForAnyPress(); // rotate the motor TO 1440 degrees // (so which way should be motor rotate?) // and, returning AFTEF complete, so // your OINK should be delayed: Motor.B.rotateTo(1440); LCD.drawString("DELAYED OINK!", 0, 4); LCD.drawString("near 1440? " + Motor.B.getTachoCount(), 0, 5); Button.waitForAnyPress(); // now try to rotate TO 0, BUT with a // second argument of true, // so you should see this OINK BEFORE // the rotations are complete Motor.B.rotateTo(0, true); LCD.drawString("NOT-DELAYED OINK!", 0, 6); // please wait again for rotation to stop // before pressing the button... Button.waitForAnyPress(); LCD.drawString("near 0? " + Motor.B.getTachoCount(), 0, 7); Button.waitForAnyPress(); } }