import com.pi4j.io.gpio.RaspiPin;
public class TestServo
{
public static void main(String args[]){
// Create the range sensor
Servo servo = new Servo(RaspiPin.GPIO_27);
int j = 0;
do {
System.out.println("***** Start degree test from left to right *****");
int curPos = servo.getDegMin()-1;
// from left to right
for(int i = servo.getDegMin(); i < servo.getDegMax(); i++){
try{
servo.setDeg(i);
}catch(Exception e){
System.out.println(e.getMessage());
}
int cpos = servo.getPos();
if(cpos > curPos){
curPos = cpos;
System.out.print("\n "+curPos+" : ");
}
System.out.print(i+" , ");
}
System.out.println("***** Start degree test from right to left *****");
curPos = servo.getDegMax() + 1;
// from left to right
for(int i = servo.getDegMax(); i > servo.getDegMin(); i--){
try{
servo.setDeg(i);
}catch(Exception e){
System.out.println(e.getMessage());
}
int cpos = servo.getPos();
if(cpos < curPos){
curPos = cpos;
System.out.print("\n "+curPos+" : ");
}
System.out.print(i+" , ");
}
j++;
} while (j < 5);
servo.release();
}
}