import com.pi4j.io.gpio.*;
public class TestDrive
{
public static void main (String args[]){
Drive d = new Drive(com.pi4j.io.gpio.RaspiPin.GPIO_01,RaspiPin.GPIO_26,RaspiPin.GPIO_23,RaspiPin.GPIO_24);
try{
// play
int j = 0;
while (j < 10){
// forward
System.out.print("forward: ");
for(int i = 0; i < d.getSpeedMax(); i++){
d.forward(i);
sleep(10);
}
sleep(2000);
System.out.println("...");
// stop
System.out.println("Stop");
d.stop();
sleep(2000);
// backward
System.out.println("backward");
for(int i = 0; i < d.getSpeedMax(); i++){
d.backward(i);
sleep(10);
}
// stop
System.out.println("Stop");
d.stop();
sleep(2000);
// turn left
System.out.println("turn left");
for(int i = 0; i < d.getSpeedMax(); i++){
d.turnLeft(i);
sleep(10);
}
// stop
System.out.println("Stop");
d.stop();
sleep(2000);
// turn right
System.out.println("turn right");
for(int i = 0; i < d.getSpeedMax(); i++){
d.turnRight(i);
sleep(10);
}
sleep(2000);
// stop
System.out.println("Stop");
d.stop();
j++;
sleep(2000);
}
} catch(Exception e){
// nothing to do wrong speed value
System.out.println(e.getMessage());
} finally {
GpioController gpio = GpioFactory.getInstance();
gpio.shutdown();
d.release();
}
}
public static void sleep(long s){
try{
Thread.sleep(s);
} catch (Exception e) {
// do nothing shit happends
}
}
}