Ease Servo Movement

By Dan Chen, May 9, 2015

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

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

#include

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(A1); // attaches the servo on pin 9 to the servo object
}

void loop()
{
for(pos = 1; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees { float t1 = (float) (pos - 1) / (float) (180 - 1); float t2 = (float) (180 - pos) / (float) (180 - 1); myservo.write(pos); // tell servo to go to position in variable 'pos' delay( 5+pow (max(t1, t2), 6) * 30); // waits 15ms for the servo to reach the position } for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
//float t = (float) (180 - pos) / (float) (180 - 1);
float t1 = (float) (pos - 1) / (float) (180 - 1);
float t2 = (float) (180 - pos) / (float) (180 - 1);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay( 5+pow (max(t1, t2), 6) * 30); // waits 15ms for the servo to reach the position
}

}

Check out this GIT HUB for easing without delay

https://github.com/todbot/ServoEaser