Youtube video of ServoEasing in action
This is an extension to the Arduino Servo library for smooth servo movements.
- Linear as well as other ease movements for all servos attached to the Arduino Servo library are provided.
- All servos can move synchronized.
- It enables non blocking movement for all servos attached to the Arduino Servo library by reusing the interrupts of the servo timer.
- Linear
- Quadratic
- Cubic
- Quartic
- Sine
- Circular
- Back
- Elastic
- Bounce
- User defined
Until now, only one timer is supported, which means not more than 12 servos are supported.
This example shows symmetric (end movement is mirror of start movement) linear, quadratic and cubic movements for 3 servos synchronously.
This example shows asymmetric (end movement is different from start movement) partially user defined (line 140) non linear movements for 3 servos synchronously.
This example helps you determine the right end values for your servo.
These values are needed for the attach()
function, if your servo does not comply to the standard values.
E.g. my SG90 servos have a 0 degree period of 620 µs instead of the standard 544.
This example does not use the ServoEasing functions.
This example gives you a feeling how fast your servo can move.
This example does not use the ServoEasing functions.
If you have only one or two servos, then you can save program space by defining symbol USE_LEIGHTWEIGHT_SERVO_LIB
.
This saves 742 bytes FLASH and 42 bytes RAM.
Using the included Lightweight Servo Library makes the servo pulse generating immune to other libraries blocking interrupts for a longer time like SoftwareSerial, Adafruit_NeoPixel and DmxSimple.
To define the symbol in the Arduino IDE, use Sketch/Show Sketch Folder ( Ctrl+K)
then navigate to the src
folder, open ServoEasing.h and outcomment line 20.
If not using the Arduino IDE take care that Arduino Servo library sources are not compiled / included in the project.
If you do not need the more complex easing functions like Sine
etc., which in turn need sin(), cos(), sqrt() and pow(), you can shrink library size by approximately 2100 bytes by defining the symbol KEEP_LIBRARY_SMALL or comment out line 34 in ServoEasing.h.
The ServoEasing library examples are built on Travis CI for the following boards:
- Arduino Uno
- Arduino Leonardo
- Arduino cplayClassic
- Arduino Mega 2560
Please write me a PM including your motivation/problem if you need a modification or an extension e.g. a callback functionality after move has finished.