Hi, when moving a servo from 0 to 180 degrees, i realize a delay of 15-20ms must happen or otherwise it wont be able to get to 180 degrees. Meaning if i make the delay 10ms it would go 90degree then go back to its original position which i set to 0 degrees.
Now....its annoying because each degree needs 15-20ms to complete so by the time it goes from 0-180 degrees, that's kinda slow, but the funny part is when it does back from 180 degrees to its starting position, its a lot faster.....how can i reach that speed of the servo while going to my position the same way it goes back to its original position.
#include <Servo.h>
Servo myservo;
const int angleIncrement = 1;
const int incrementDelay = 10;
void setup() {
// put your setup code here, to run once:
myservo.attach(7);
}
void loop() {
for (int angle = 0; angle < 180; angle += angleIncrement) { // single "degree" increments
myservo.write (angle);
delay (incrementDelay); // so we'll take 10 * 180 milliseconds = 1.8 seconds for the traverse.
}
}
If you want to control the speed of a servo, there are the VarSpeedServo and MobaTools servo libraries that make it pretty easy to do and non-blocking, unlike your for loops.
Does it wait for 20ms to expire if there's a new servo.write() before then? I know it refreshes every 20ms (by default, and yes @nice_servo you can change that in the library source) when a new value is not sent; I've 'scoped that before. But I've never 'scoped to see if a new write causes a new signal to the servo before the normal update time.