Go Down

Topic: Suggestion on how to change the speed of servo (Read 358 times) previous topic - next topic

orbs

Hey guys,
I want to have different speed serving for my servomotor.  I would like to ask how should I do it?  From the sweep code below that I am currently using, if I wanted to adjust the speed do I adjust either the delay or the increment?  Appreciate any helpful feedback.


Servo myservo;  // create servo object to control a servo
     
int pos = 0;    // variable to store the servo position

void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}


void loop()
{
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

AWOL

#1
Oct 12, 2012, 11:31 pm Last Edit: Oct 12, 2012, 11:33 pm by AWOL Reason: 1
Well, you could make the parameter of "delay" a variable, or for bonus points, get rid of "delay" altogether.

I'm a bit bored saying this but
Code: [Select]
for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees clearly it doesn't.
It would be better not to bother with the comment.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

johnwasser


From the sweep code below that I am currently using, if I wanted to adjust the speed do I adjust either the delay or the increment?


Using a larger increment or smaller delay will increase the speed.  Using the next available increment value (2) will double the speed.

Using a larger delay will decrease speed.  You can't use an increment less than 1.

You will have more range of control by changing the delay.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy