Servo controlling function...

Hi my name is Theo and i have some continue rotation futaba servos from parallax and i'v tried to programm my arduino so to tell in one servo to work for specific time and i failed .I tried the following but i haven't something better.
Code:
do {
digitalWrite(ServoPin,HIGH);
delayMicroseconds(1700);
digitalWrite(ServoPin,LOW);
delay(20);
if(millis() > 5000) {
break;
}
}
while(millis() <= 5000);

If someone can help me write a function to do that please post here and give me directions so to make the function or if you can make the function yourselves and then explain how it works.
Thanks for reading.
:slight_smile: :slight_smile: :slight_smile: :slight_smile:

Have a look at the Servo library, in particular the "writeMicroseconds" method.

"millis ()" returns the number of millisconds since you reset the Arduino, so after the first five seconds " if(millis() > 5000) {" will always be true. You need to use the difference between the time "now" and the time you decided to start.

do {
        digitalWrite(ServoPin,HIGH);
        delayMicroseconds(1700);
        digitalWrite(ServoPin,LOW);
        delay(20);
        if(millis() > 5000) {
                      break;
           }
      }
while(millis() <= 5000);

Isn't that redundant?
And also, that's a weird way of driving servos. With the servo library, you could just do something like,

Servo.write(150);
delay(5000);
Servo.write(90);

Obviously you can't just copy and paste this into arduino, but do you get what I mean?
Try looking up the servo library.

Yes i have tried also this one but i remember that i had some problems .
For example when i said to the arduino to start using the servos
arduino did it but the servos were shaking right and left all time while they were working.
I will try it again and i'll tell you the results.
Stay tuned... :slight_smile: :slight_smile: :slight_smile:

I tried this one:
#include <SoftwareServo.h>

SoftwareServo servo1;

void setup()
{
pinMode(2, OUTPUT);
servo1.attach(2);

}

void loop()
{
servo1.write(0);
delay(20);
servo1.write(180);
SoftwareServo::refresh();

}

but its the same think , i cant control the time the servo is working .
the delay is not the time the servo will work but the time between the pulses .If you know something about it tell me...

the delay is not the time the servo will work but the time between the pulses

Are you saying you want to control the time it takes for the servo to travel from, say 0 to 180 degrees.

Or are you trying to affect the PPM frame time?

Can you explain what it is you want to do, so thennn maybe we can help you better.

(BTW, I don't think people use SoftwareServo much anymore - the current Servo library is more versatile)

ok ,i want to tell a servo to work for specific time .for example
2 seconds and thenn the servo will stop ,or do something else
...

To stop your "servo", simply call the "detach" method after the appropriate delay.
This will stop the update pulses.
Call the "attach" method just before you next want to move the "servo"".

Also, in the example that doesn't work using the library, you wrote,
delay(20);

No wonder it was jiggling back and forth rapidly!
That's a fiftieth of a second.

Try
delay(2000);

And if they are continuous rotation, doesn't it mean that writing 90 to it will stop it?

And if they are continuous rotation, doesn't it mean that writing 90 to it will stop it?

Only if you're very, very lucky.

[edit]Hey! I just noticed I'm though a thousand posts! Does that mean I get a gold star, or something?[/edit]

Hey! I just noticed I'm though a thousand posts! Does that mean I get a gold star, or something?

Here you go! :smiley: