The project we're currently doing for class is requiring us to use a few servo motors to create an animatronics bat. However I am having coding problems with the servo's. They simply work fine, it will go from one degree to the next, but when it resets to it's original position and goes the other way it seems to jerk real fast and does not look smooth at all.
Any help on how to fix this would be helpful!
Here is my code, it is similar to the one on the arduino reference website, I've just added in a few extra lines.
#include <Servo.h>
Servo myservoA;
Servo myservoB;
int pos = 0; // variable to store the servo position
void setup()
{
myservoA.attach(9);
myservoB.attach(8);
}
void loop()
{
for(pos = 50; pos < 1; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservoA.write(pos); // tell servo to go to position in variable 'pos'
(15); // waits 15ms for the servo to reach the position
}
for(pos = 140; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservoA.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
{
for(pos = 90; pos < 50; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservoB.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for(pos = 0; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservoB.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
}
}