import lejos.nxt.*;
/**
 * allows interruption of a rotation task
 * @author Roger
 */
public class RotInterrupt
{
    /**
     * This method has the logic - rotate 720, return, wait for button
     * then rotate to 0 - wait for button
     * Another way to get results to the lcd
     */
    public void go()
    {
        System.out.println("Interrupt  \n rotation");
        Sound.twoBeeps();
        Button.waitForPress();
        Motor.A.rotate(720,true);
        showRotation(1);
        Motor.A.rotateTo(0,true);
        showRotation(1);
    }
    /** 
     * helper method - saves repeated code
     */
     public void showRotation(int row )
    {
        while(Motor.A.isRotating())
        {
            LCD.drawInt(Motor.A.getTachoCount(),4, 0, row);
            if(Button.readButtons()>0) Motor.A.stop();
        }
        while(Motor.A.getActualSpeed()>0);
        LCD.drawInt(Motor.A.getTachoCount(), 4,8,row);
        Button.waitForPress();
    }
    /**
     *  Main reduced to one line
     */
    public static void main(String[] args)
    {
        new RotInterrupt().go();
    }

}