The servo will always move at 'full speed' to the position you set. If you want it to move slowly, you need to give it incremental moves as in the example code:
- Code: Select all
for (uint16_t pulselen = map (120,0,180,SERVOMIN,SERVOMAX); pulselen < map (180,0,180,SERVOMIN,SERVOMAX); pulselen++)
{
pwm.setPWM(servonum, 0, pulselen);
}
If you want to change the speed of the move, you can add a delay inside the loop:
- Code: Select all
for (uint16_t pulselen = map (120,0,180,SERVOMIN,SERVOMAX); pulselen < map (180,0,180,SERVOMIN,SERVOMAX); pulselen++)
{
pwm.setPWM(servonum, 0, pulselen);
delay(2);
}
To move in the other direction:
- Code: Select all
for (uint16_t pulselen = map (180,0,180,SERVOMIN,SERVOMAX); pulselen > map (120,0,180,SERVOMIN,SERVOMAX); --pulselen)
{
pwm.setPWM(servonum, 0, pulselen);
delay(2);
}
There are ways to clean that up and make it easier to use. But it's best if you understand this part first.