TL; DR
Impatient? Here's the short take.
- Provide suitable power to your servos See Hardware Interface..
- Download and install the Sweeper Library.
- Start with the example sketches provided, experiment and learn. See the video to see them in action.
- Read more when you need to know more.

Hardware Interface
- Servos need independent power! Initially, I used a 6V, 1A wall wart. Ran 6 SG-5010 and 2 SG90 servos simultaneously for a few minutes and the wall wart was just barely warm. I didn't try to find the limits of this setup. It worked for testing. Servos are really happiest (most of them) with 5V, not 6V. So I'm now using a 5V, 2A switching supply. If you use a lot of motors (more than 4 to 6 or so?) you may need a beefier supply. YMMV. If your motors are loaded heavily, obviously you'll need more power. Test your system by running a single motor, then add more one at a time. If the motors stop moving reliably, then you should increase the power available. The worst case is likely to be when several motors all need to move rapidly at the same time.
- I built a simple board to connect power and the control signals. The schematic and a picture of it are attached. (See ServoIntrf.png and ServoInterface.pdf.) Doesn't get much simpler. The two big caps are there to smooth out surges during servo motion. But if you aren't into building hardware,  simply search Ebay for "Sensor Shield Digital Analog Module Servo Motor for Arduino UNO R3". The file ServoBoard.jpg shows a picture. For about five bucks with shipping, this is a good way to go.

Installing the Sweeper Library

Sweeper.zip is the zipped Sweeper library. To install library, download the zip, open the Arduino IDE, go to Sketch > Include Library > Add .ZIP Library, and then select the Sweeper zip file that you just downloaded. No need to restart Arduino, the Sweeper Library will now be available. Note that you must also install the Servo library, if it's not already done, to use the Sweeper library. The elapsedMillis library must be installed to run the demos. These can be installed with the Library Manager.

Why we need a Sweeper Library

A Sweeper object is really just a Servo object with some software controls to make it easier to use. A Sweeper is simply a servo with controlled movement. Desired position and move time can be specified for each Sweeper. The millisecond timer (Timer0) is used to position each Sweeper appropriately once per millisecond. Behind each Sweeper object is a Servo object.

A servo motor, the physical device represented by a Servo object, is a DC motor with a gear box, to trade speed for force, and an electronic interface. The electronic interface receives a 1 to 2 millisecond pulse every 20 milliseconds. The width of the pulse, between 1 and 2 milliseconds, represents an angle between 0 and 180 degrees. Receiving a new pulse every 20 milliseconds means an update rate of 50 times per second. A servo motor has a potentiometer connected to its shaft to provide feedback to the electronic controller so that the rotation can be precisely controlled. When a given angle is commanded by the correct pulse width, the controller moves the servo until the potentiometer measures the value corresponding to the desired angle.

Small servo motors were originally developed for radio-controlled planes and boats. They were made to move to a new position as quickly as possible. This makes them great for controlling model airplanes, but often not so good for making automata (for example) move in a realistic manner. The purpose of the Sweeper library is to provide the ability to move a Servo to a desired position at a desired rate. Using the Sweeper library, a Servo can be moved to 75 degrees in 10 seconds (for example) if desired. While doing this for one Servo (without the Sweeper library) is pretty easy, doing the same for multiple Servos moving to various angles in various times is difficult! Using the Sweeper library, it's not difficult at all as the examples will show.

The Servo library uses one of the timers in the Arduino microprocessor to create pulses to control servo motors hooked to Arduino pins. Each Servo object controls one servo motor. Reading the documentation for the Servo library is highly recommended.

Sweeper Library Details:

Sweeper - Class for manipulating servo motors connected as Sweepers to Arduino pins.

Class Methods:

    sweepAttach(pin)     - Create a Servo to be used as a Sweeper and attach it to a pin.
    sweepDetach()        - Detaches the servo associated with a Sweeper from the pin.
    setTarget(newTarget, deltaTime)   -  newTarget in degrees; deltaTime in milliseconds - but wait for goNow to move.
    setTargetGo(newTarget, deltaTime) -  newTarget in degrees; deltaTime in milliseconds - move immediately.
    goNow ()     - along with setTarget, allows servos to be set up, then quickly triggered.
    sweepDone ()    - returns true if a programmed sweep is done; false if not
    sweepReset()       - Move Sweeper to mid range (reset) position immediately.
    resetTo(startPos)     - Move the Sweeper immediately to startPos.

Example Programs:

These are included with the Sweeper Library. As the names imply, these are designed and tested on an Uno. They will work equally well on a Teensy2 and probably most other Arduinos based on the ATMega32 architecture.


UnoKnobServoTestDemo - This sketch is modified from the Servo Library examples and is included as a convenience. It is a sketch for testing a servo and defining its limits. Turning the pot changes the position of the servo. The position is reported on the Serial Monitor. The values reported can be used to specify desired movement of a sweeper.

UnoSweeperDemo1 -  This sketch creates a single Sweeper object. It demonstrates the simplest use of the Sweeper library. The servo on the servoPin will be positioned at 90 degrees, then swept (as a Sweeper object) between 50 and 150 degrees. Experiment with this sketch to learn how the Sweeper Library can control speed and angle of a servo.

UnoSweeperDemo2 - This sketch uses the Sweeper library to create and use 2 Sweepers. They will make random moves at random times. This sketch also illustrates how to create an array of Sweepers. Of course, it is not necessary to use the array approach. Each Sweeper could be given a unique name. The use of elapsedMillis is also of interest in this sketch.

UnoMultiSweeperDemo4 - This sketch is designed to work with a 4 servo demo rig I have. Using groupMove, the four servos will move in unison. Take a look at the YouTube video to see it in action. I include the sketch here as a demo. You must provide your own servo system

Additional Notes

Although the code is running on an Arduino Uno, it will run equally well on a Teensy 2 or a Mega. It WILL NOT run on a Teensy 3 or other ARM-based Arduinos. I'll need to figure out more about the ARM timers and perhaps the interrupt structure. Future work!

Because this program uses T/C0 Output Compare A, that output is unavailable for PWM. Same for T/C1 which is used by the Servo library. For UNO, this means no PWM on D9, D10, or D6. For Teensy 2, no PWM on D4, D14, or D15.

A few details of the Sweeper Library are worth explaining.

The ATmega328P (as used on Arduino UNO) and the ATmega32U4 (as used on Teensy2) have many hardware resources that are not used, or not fully exploited, by Arduino. A full description is well beyond this discussion, but a small consideration is appropriate. Let's focus narrowly on the Timer/Counters. Specifically, let's look at T/C0. T/C0 is configured in Arduino to overflow and cause an interrupt at a rate very close to 1 KHz. This interrupt updates millis. Of course, this action is mostly invisible to the Arduino user. The millis function just magically works - or so it seems. What Bill Earl (see AdaFruit reference in my first Build Log) did was to read the data sheet for the ATMEGA328P very closely and discover that T/C0 could be used to do more than just keep track of millis. T/C0 can also generate another interrupt whenever a specific count value is reached. The Output Compare A of Timer 0 will be configured to generate an interrupt in addition to the one used for millis. That interrupt is used to update the commands to the servos to control their movement and rate of movement. You can learn a lot more about other resources of the AVR processors at the AVRFreaks web site.
T/C0 is configured to count continuously starting at 0 and continuing to 255. Upon reaching 255, T/C0 resets to 0 and starts counting again. If the Output Compare A register of Timer 0 has a value in it, and its interrupt is enabled, then, when the T/C0 count reaches that value, an interrupt will occur. When an interrupt occurs, the processor saves the system state and jumps to an Interrupt Service Routine for the specific interrupt. There is a table of ISRs used for this purpose. To create an entry in this table, the macro ISR is invoked with the name of the interrupt as an argument. In our case, the line

ISR (TIMER0_COMPA_vect) 

declares the code in braces following the declaration to be that which will be executed whenever the T/C0 Compare A overflows. An entry for the vector is put into the ISR table. The name of the ISR vector must be one that is known to the compiler for the processor being used. No further definition of the name is needed. The names (and other hardware information specific to a processor) may be found in [arduino base]/hardware/tools/avr/avr/include/avr. For UNO, look at iom328p.h and for Teensy 2, look at iom32u4.h. The appropriate data sheet will also indicate the desired interrupt vector. Table 9-1 in Section 9.1 of the ATmega32u4 data sheet gives the name of the vector needed. The precise name must be found in iom32u4 data sheet. Note that this is hardly a complete description of interrupt handling, just enough to explain what's going on and to pique your curiosity.

To make use of the T/C0 OCR0A, we must do two things. First, we must put a value into the register that will be compared to the T/C0 count. That's OCR0A. Then we must set the correct bit in the T/C0 control register to enable the interrupt. That bit is OCIE0A and we must OR the bit into register TIMSK0. More careful reading of the data sheet required! The code looks like this:

  OCR0A = 0xAF;
  TIMSK0 |= _BV(OCIE0A);

You won't find these names defined in the Arduino code - at least not in an obvious place. They come from the processor data sheets. The Arduino user is mostly spared the details, but if you want to do the sort of work Bill Earl does, you'll want to learn all about this stuff by reading the data sheets! For T/C0, you'll find the names of the registers and the bit definitions in Section 13.8 of the ATmega32u4 data sheet.
To actually move the servos, the Arduino Servo library is used. It can control up to 12 servos and uses Timer Counter 1 for appropriate interrupt-based timing. The Update function in the Sweeper class calls the Servo library to make the moves when it's time for each servo.