Mover
import java.io.File;
 
import lejos.nxt.MotorPort;
import lejos.nxt.NXTRegulatedMotor;
import lejos.nxt.Sound;
 
/**
 * Basecode is copied from Ole Caprani's Car.java
 * 
 */
public class Mover {
    private final static int forward  = 2,
            backward = 1,
            stop     = 3;
 
    private static MotorPort leftMotor = MotorPort.C;
    private static MotorPort rightMotor= MotorPort.B;
    private static NXTRegulatedMotor hammer = new NXTRegulatedMotor(MotorPort.A);
 
    private final static int power = 75;
    private final static int steeringPower = 65;
    private final static int backPower = 65;
 
    public static void stop()
    {
        leftMotor.controlMotor(0,stop);
        rightMotor.controlMotor(0,stop);
    }
 
    public static void forward()
    {
        leftMotor.controlMotor(power,forward);
        rightMotor.controlMotor(power,forward);
    }
 
    public static void backward()
    {
        leftMotor.controlMotor(backPower,backward);
        rightMotor.controlMotor(backPower,backward);
    }
 
    public static void left()
    {
        leftMotor.controlMotor(steeringPower+5, backward);
        rightMotor.controlMotor(steeringPower, forward);
    }
 
    public static void right()
    {
        leftMotor.controlMotor(steeringPower, forward);
        rightMotor.controlMotor(steeringPower+5, backward);
    }
 
    public static void attack()
    {
        if (hammer.getPosition() == 0) {
            Sound.playSample(new File("hit.wav"));
            hammer.rotateTo(100);
        } else {
            int speed = hammer.getSpeed();
            hammer.setSpeed(130);
            hammer.rotateTo(0);
            hammer.setSpeed(speed);
        }
    }
 
    public static void quit() {
        stop();
        hammer.setSpeed(130);
        hammer.rotateTo(0);
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License