Trouble with Servo Breakout & Wave Shield.
Moderators: adafruit_support_bill, adafruit

Re: Trouble with Servo Breakout & Wave Shield.

by unorthodoxarts on Wed Jan 16, 2013 8:54 pm

Oh. Hahah. I see. The 'pulselen' in the pwm.setPWM() thing is a placeholder. Ahhah!

The only thing now, is that the 'delay' after the pwm.setPWM() doesn't control the speed at which the servo moves, but the gap in between them moving. Is there any way to slow down the rate it moves?

Thank you again.
unorthodoxarts
 
Posts: 11
Joined: Fri Dec 28, 2012 1:13 pm

Re: Trouble with Servo Breakout & Wave Shield.

by adafruit_support_bill on Thu Jan 17, 2013 5:45 am

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 | TOGGLE FULL SIZE
  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 | TOGGLE FULL SIZE
  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 | TOGGLE FULL SIZE
  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.
User avatar
adafruit_support_bill
 
Posts: 29813
Joined: Sat Feb 07, 2009 9:11 am