Hi, I'm relatively new to arduino and programming but I'm working on this project now and I want to move 4 servos simultaneously and also to set the speed of the servo motors . I've managed to make the servos move simultaneously but I can't figure out now how to set the speed . This is the code I've written so far :
} And prior to this I've managed to also set the speed of the servo with this algoritm, but couldn't make the servos move simultaneously : #include <VarSpeedServo.h> VarSpeedServo servo1; const int servo1Pin=10; void setup() { servo1.attach(servo1Pin); servo1.write(0,255,true); delay(3000); } void loop() { * servo1.write(0,120,true);* * delay(1000);* * servo1.write(150,120,true);* * delay(1000);* }
If you have any idea how i could make them servos move simultaneously and also set their speed that would be awesome. Thank's !
I know nothing about the VarSpeedServo library and it is not necessary.
Look at how the servo is controlled in the servo sweep example and in planning and implementing a program. Basically the servo is moved a little piece at a time with a suitable interval (to govern the speed) between each small movement.
You can use the same technique with several servos. You can use the same interval for all servos if they are all to move at the same speed, or different intervals for each of them.
Are all four servos going to the same destination at the same rate? If so, hook them all to the same output pin and use the ServoSweep example to control the speed.
If they are moving different amounts, did you want them to all use the same speed or all finish at the same time? Is the time or the maximum speed fixed? Fixed time would mean a short move would be slower than a long move. Fixed maximum speed would mean the time would depend on the longest move.
Varspeed library is a simple way to do it. But to make it work you have to drop the delay(). (Delay() is stupid anyway :p) See Blink without delay on how to do it without.