Loading...
Pages: [1]   Go Down
Author Topic: Suggestion on how to change the speed of servo  (Read 176 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
  }
}
Logged

Global Moderator
UK
Online Online
Brattain Member
*****
Karma: 143
Posts: 19374
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
« Last Edit: October 12, 2012, 04:33:07 pm by AWOL » Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 108
Posts: 6611
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Print
 
Jump to: