Servo Movement. Help!

I want to control two servos to move back and forth while increasing their speed and when they reach max speed, to stop. Then, wait for a couple of seconds and start the loop again.
Any idea how to make it? I've been trying with the sweep code at differents steps

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 = 0; pos < 180; pos += 5)  // 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 
  }

But it dosen't seem to work.
Then, I tried with the Varspeedservo lib, but I keep getting this error when compiling:

'VarSpeedServo' does not name a type

I tried with Arduino 1.0 and 1.0.1
I'm kind of newbie so any help will be helpful!
Thanks from Chile

while increasing their speed and when they reach max speed, to stop.

Basically you cannot control the speed of a servo movement.
You might get a little success by commanding it to move in small increments with a delay between each command but that is all.
Why on earth do you want to do this?

As mike stated a servo's maximum speed is fixed and determined only by the servo. You can however slow the apparent speed of the servo by taking more time between sending each new incremental position command. In your sketch you are using a fixed time delays between each new increment command where if fact you want to make the amount of time delay to be a part of your speed control method, so possibly use a delay(x) where x is a changing value as you command the servo from fastest to slowest speed.

As far as the library you tried, unless you post a link to it for us it's hard to see if you are using it correctly or not and if it can do what you want or not.

Lefty

Thanks for the replies...

So I must change the delay between each increment? Something like this:?

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
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() 
{ 
  slowspeed();
  delay(15);
  medspeed();
  delay(100);
  fastspeed();
  delay(1000);  
 
}

void slowspeed(){
  for(pos = 0; pos < 180; pos += 2)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 2 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
  }
 delay(15);
}

void medspeed(){
  for(pos = 0; pos < 180; pos += 5)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 5 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
  } 
  delay(50);
}

void fastspeed(){
  for(pos = 0; pos < 180; pos += 9)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 9 degree 
    myservo.write(pos);      // tell servo to go to position in variable 'pos' 
  } 
  delay(150);
}

But it's not working... the servo seems stuck.

So whats the VarSpeedServo lib for? I thougth it was to controll the speed of a servo?
The code I'm using is one I got from another post

#include <VarSpeedServo.h>

int pos = 0;    // variable to store the servo position 
VarSpeedServo myServo; 
void setup() 
{ 
myServo.attach (9);
} 
 
 
void loop() 
{ 
  for(pos = 0; pos < 180; pos += 180)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
  myServo.slowmove (pos,1);             // 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-=180)     // goes from 180 degrees to 0 degrees 
  {                                
    myServo.slowmove (pos,1);
  
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

The idea is the servo moves 90° (form point A to point B, back and forth) continuously while the speed of the movement increases in the meanwhile
until it reaches the maximun speed posible and it stops...This project is part of a bigger project I'm working on, which involes a kind of performatic device...

Well your slowest speed function is using the shortest delay and your fastest speed function is using the longest delay, does that sound logical and correct to you? Less time delay = faster for loop cycle time so servo commands sent faster. Also all your for statements should just increment the position by one degree each cycle.

Yours

for(pos = 0; pos < 180; pos += 2)
for(pos = 0; pos < 180; pos += 5)
for(pos = 0; pos < 180; pos += 9)

All those should just increment by 1 degree each iteration, so:

for(pos = 0; pos < 180; pos++)

So whats the VarSpeedServo lib for?

I don't have a clue as you have yet to send a link to where someone can find that library.

Lefty

We should also asK - how are you powering the servos ?

Check the two links below for why this matters and a quick fix.

Duane B

Well your slowest speed function is using the shortest delay and your fastest speed function is using the longest delay, does that sound logical and correct to you? Less time delay = faster for loop cycle time so servo commands sent faster. Also all your for statements should just increment the position by one degree each cycle.

I changed the delay on the functions but its still not working...the servo just makes like small quick movements

don't have a clue as you have yet to send a link to where someone can find that library.

Here's the link http://arduino.cc/forum/index.php/topic,61586.0.html

We should also asK - how are you powering the servos ?

Check the two links below for why this matters and a quick fix.

Thaks for the links Duane
Just for quick testing the code I'm using a micro servo connected to the 5v arduino entry. I think its enough? There's nothing else conected to it...

The delay need to be inside the for loop so it happens on every step. As you have it you only delay after outputting all the steps in a sweep.