Looking at the PWM signals generated by the normal Servo library, you can see that the puls width varies between 500 μs and 2300 μs. This means that it is possible to select the servo position in centi-degrees. However, the library limits ba default the puls-width to 2000 μs; the default values need to be altered. The code looks like this:
const uint8_t LEFT=0;
const uint8_t RIGHT=1;
uint8_t nP[2][8] = {{ 0,17, 9,10,11,12,13,14},{18,17, 1, 2, 3, 6, 7, 8}};
const int Smax=1800;
const int Smin=500;
#include <SoftPWMServo.h>
int pos = 0;
const int pin = nP[RIGHT][7]; // Choose _any_ pin number on your board
void setup()
{
SoftPWMServoInit();
SoftPWMServoSetFrameTime(100000); // 2500 us are 100000 tics for 40 MHz CPU!
SoftPWMServoSetServoFrames(8); // 8 frames make 20 ms wavelength
}
void loop()
{
for (pos=0; pos <= 1800; pos+=2) // use deci-degree in 0.2 degree steps
{
SetServoPos_decidegree(pos);
delay(5);
}
for (pos=0; pos <= 1800; pos+=2) // use deci-degree in 0.2 degree steps
{
SetServoPos_decidegree(1800-pos);
delay(5);
}
for (pos=0; pos <= 180; pos++) // use degree in 1 degree steps
{
SetServoPos_degree(pos);
delay(25);
}
for (pos=0; pos <= 180; pos++) // use degree in 1 degree steps
{
SetServoPos_degree(180-pos);
delay(25);
}
SetServoPos_degree(90);
delay(1000);
SetServoPos_degree(180);
delay(1000);
SetServoPos_degree(0);
delay(1000);
}
void SetServoPos_degree(int degree)
{
SoftPWMServoServoWrite(pin, 10*degree+Smin);
}
void SetServoPos_decidegree(int decidegree)
{
SoftPWMServoServoWrite(pin, decidegree+Smin);
}
The code drives the servos once from 0 to 180 degrees in 0.2 degree steps and back, then again but in 1 degree steps. At the end the positions 90°, 180° und 0° are selected for a second each.