VarSpeedServo - a modified Servo library with speed control

Hello, all.
I'm very happy to have found a servo library that has variable speed. Thank you for posting it, Korman. A funny thing is happening though. The code that would work with Servo.h, where I call functions in sequence, isn't working here. The slow speed is fantastic, but I'm having difficulty sweeping the servos between positions on a loop like I was with the original library. It stops at the first position in the loop, without going further. Any suggestions?

#include <VarSpeedServo.h>







VarSpeedServo RR;
VarSpeedServo RL;
VarSpeedServo MR;
VarSpeedServo ML;
VarSpeedServo FR;
VarSpeedServo FL;

//int pos =90;
int fanPin = 1;


void setup(){
  pinMode(fanPin, OUTPUT);
  digitalWrite(fanPin, HIGH);
  RR.attach(5);
  RL.attach(9);
  MR.attach(4);
  ML.attach(10);
  FR.attach(3);
  FL.attach(11);
  RR.slowmove(90,255);
  RL.slowmove(90,255);
  MR.slowmove(90,255);
  ML.slowmove(90,255);
  RR.slowmove(90,255);
  RL.slowmove(90,255);
   }

void loop(){
  RR.slowmove(90,255);
  RL.slowmove(90,255);
  MR.slowmove(90,255);
  ML.slowmove(90,255);
  RR.slowmove(90,255);
  RL.slowmove(90,255);
  delay(150);
  yawRight();
  delay(150);
 // yawLeft();
  
  }

 
 
 void yawRight(){
 
  FR.slowmove (65, 15);
  FL.slowmove (65, 15);
  MR.slowmove (65, 15);
  ML.slowmove (65, 15);
  RR.slowmove (65, 15);
  RL.slowmove (65, 15);
  
  
 }
 void yawLeft(){
  FR.slowmove (115, 15);
  FL.slowmove (115, 15);
  MR.slowmove (115, 15);
  ML.slowmove (115, 15);
  RR.slowmove (115, 15);
  RL.slowmove (115, 15);
  }

Found on GitHub a working SAM (Due) working version of this awesome lib, tested and it work like a charm.

C:\Users\robert\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:56:23: fatal error: WProgram.h: No such file or directory

#include <WProgram.h>

^

compilation terminated.

Error compiling.

I keep getting this error message. Any help?

C:\Users\robert\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:56:23: fatal error: WProgram.h: No such file or directory

#include <WProgram.h>

^

compilation terminated.

Error compiling.

I keep getting this error message. Can any help? Here's my code.

#include <VarSpeedServo.h>
VarSpeedServo servo;

#define servoControl 6

void setup() {
servo.attach(servoControl);
}

void loop() {
servo.slowmove(85, 50);
delay(1000);
servo.slowmove(0, 50);
delay(1000);
}

C:\Users\robert\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:56:23: fatal error: WProgram.h: No such file or directory

You will need to change WProgram.h to Arduino.h in the .h and .cpp files.
You may need something like notepad ++ or CodeBlocks if you don't have either

https://notepad-plus-plus.org/

good luck!

Hey everyone...let me first explain I'm very...very new! to all this arduino programming but I have found this page and it's exactly what I need!!....but...I've downloaded it and tried to do a very easy sketch to control a servo from
0 to 90 degrees..
Delay a second
90 to 180 degrees
Delay a second..and then to just continue this sequence.

Every time I try it it comes up with a fault!!

Is the any chance one of you professionals could show me a complete sketch on here as I'm at the end of my patience and am gonna smash this laptop up soon!!

It would be sooooo much appreciated!!

Thanks..

Programming newbie trying to get VarSpeedServo.h to work with no luck. I'm using IDE 1.6.8

Please enlighten me as to the (hopefully) silly step I'm missing!

I downloaded the zip file attached to the second message here, unzipped it and installed it with the other libraries, and am able to include it from the 'include library' menu.

If I open and compile the standard Sweep sketch, that compiles fine. When using the VarSpeedServo.h library instead of Servo.h I get errors.

I've tried the suggestions I found here: tried changing the WProgram.h to Arduino.h in the .cpp file (it does not exist in my .h file) with no change.

I've tried compiling for different boards with no change.

All I'm doing is deleting the line #include <Servo.h> and inserting #include <VarSpeedServo.h>.

#include <VarSpeedServo.h> gets inserted at the top of the sketch automatically from the Include Library menu -- so I cut it from the top and paste it into the line where #include <Servo.h> was. (Leaving it at the top doesn't make any difference though).

An interesting note: the library manager says 'VarSpeedServo Built In Version unknown INSTALLED' and no other info.

/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <VarSpeedServo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

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 >= 0; 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
  }
}

And the error messages...

Build options changed, rebuilding all
Sweep:14: error: 'Servo' does not name a type

 Servo myservo;  // create servo object to control a servo

 ^

C:\Users\bob\AppData\Local\Temp\arduino_modified_sketch_373480\Sweep.ino: In function 'void setup()':

Sweep:20: error: 'myservo' was not declared in this scope

   myservo.attach(9);  // attaches the servo on pin 9 to the servo object

   ^

C:\Users\bob\AppData\Local\Temp\arduino_modified_sketch_373480\Sweep.ino: In function 'void loop()':

Sweep:26: error: 'myservo' was not declared in this scope

     myservo.write(pos);              // tell servo to go to position in variable 'pos'

     ^

Sweep:30: error: 'myservo' was not declared in this scope

     myservo.write(pos);              // tell servo to go to position in variable 'pos'

     ^

exit status 1
'Servo' does not name a type

callmebob, did you get it working?

If not, need to change "Servo myServo" to "VarSpeedServo myServo;"

cjones7:
callmebob, did you get it working?

If not, need to change "Servo myServo" to "VarSpeedServo myServo;"

That's correct.

I am getting this error message:
how to solve it ?
i removed Varispeedservo library and reinstalled it. I also restarted to computer..I changed the arduino board...all did not work..please help...

Arduino: 1.6.9 (Windows 7), Board: "Arduino Nano, ATmega328"

WARNING: Category '' in library EEPROM is not valid. Setting to 'Uncategorized'
WARNING: Category '' in library SPI is not valid. Setting to 'Uncategorized'
WARNING: Category '' in library SoftwareSerial is not valid. Setting to 'Uncategorized'
WARNING: Category '' in library Wire is not valid. Setting to 'Uncategorized'

Sketch_1:112: error: no matching function for call to 'VarSpeedServo::write(long int&, int, bool)'

Hi Guys

I've a problem

I had a Servo SM-S2309S with them I wanted that, he turn from 0 to 90 to 180 deegres and back. It works, but the Servo didnt reach 180 deegres, so I buyed a Motor with 360 deegrees. But now it doesnt works with the old code and only turns endless and the turn back. What's wrong?
please help the sketch is here

#include <VarSpeedServo.h>
VarSpeedServo servo;
#include <LiquidCrystal.h> // include libary
LiquidCrystal lcd(12,11,5,4,3,2); // connected Pin's with the Lcd
int const Poti= A0;
int potVal = 0;
int analogservo;

int servoSpeeds = 20;
int doublespeed = 40;
int servoneun = 90; // the maximum servo angle
int servosechzig = 160;
int servoposition = 0;

void setup() {
int const Poti = A0;
pinMode(analogservo,OUTPUT);
servo.attach(9);

servo.slowmove(servoposition,servoSpeeds) ;

}

void loop() {

if(servo.read() == servoposition)

{
servo.slowmove(servoneun,servoSpeeds) ;
lcd.clear();

lcd.print ("0");
lcd.print(" Grad");
delay(4000);

}

else if(servo.read() == servoposition + 90)

{
servo.slowmove(servosechzig,servoSpeeds) ;
lcd.clear();
delay(4000);

lcd.print ("160");
lcd.print(" Grad");
delay(4000);
}
else if(servo.read() == servoposition + 160)
{servo.slowmove(servoneun,doublespeed) ;
lcd.clear();

lcd.print ("90");
lcd.print(" Grad");
delay(4000);

servo.slowmove(servoposition,doublespeed);
lcd.clear();

lcd.print ("0");
lcd.print(" Grad");
delay(4000);
}
else{

}

}

What is the Limit to the Number of Servos i can control ?? The documentation says 8, can this be increased ??

I currently need to control 20+ servos, Using an arduino MEGA 2560 R3. (For a Humanoid)
What is my best option if i need speed control for all the servos?

I am willing to modify some code to control more servos if it is possible,
Unless someone has already done it :), Please link.

If such a Servo library is not available which can control more number of servos with SPEED control, i will try to make one and share :slight_smile: .

Can you give more specific documentation...?
I don't understand this sentence at all:
myServo.slowmove (newpos, speed);

Hi. I'm fairly new to Arduino's and very new to servo motors. I am trying to get the speed setting to work.

This is the code I have:

#include <VarSpeedServo.h>

VarSpeedServo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int speed = 0;

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

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

It uploads but then the servo just clicks and doesn't move. I know something is terrible wrong with the code but cannot work it out. Also, I would like the motor to pause when it hits 90 degrees and 0 degree but I'm not sure what the code is for that either.

Any help would be very much appreciated.

Cheers.

How are you powering your servo? Not from the Arduino 5V pin, I hope. Have you tried the "Sweep" example from the Servo library?

Thanks for your reply. The sweep example works but when I try and add the myservo.slowmove the servo stops working.

Please post your most recent code.

The code is in my first post but here it is again.

#include <VarSpeedServo.h>

VarSpeedServo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int speed = 0;

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

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

Please let us know how to control continuous rotation servo motor - To run CW rotation ( 10 turns) then it stopped until we send another command CCW rotation (3 turns)

How can i move slowly to a position when i power up the Arduino?
writeMicroseconds does not take 3 argument's and "write" always goes fast to the middle position before going to the given value on startup.