Hello, I am writing the code to control a robot. It has 2 servo 360.
I cannot make it run left and right in fact the servo is running without stopping. How can I limit the time of action of the servo?
It is important because I want that the robot turns right when, through an Android App, I click on the button "Turn Right"
Please post the code that you are using and a circuit diagram
I take it that you are using a continuous rotation "servo"
To stop such a "servo" you need to write a value of about 90 to it but the exact value will depend on the "servo". If you use writeMicroseconds and use a value of about 1500 you may get better results as it gives finer control.
The circuit is visible here: http://diymakers.es/wall-e/
I use 2 continuous rotation "servo". The code to go ahead (Avanti) and go back (Indietro) is this:
unsigned long previousMillis = 0; // last time update
long interval = 5000; // interval at which to do something (milliseconds)
void Destra() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {0
previousMillis = currentMillis;
RuotaSinistra.write(180);
}
}
Pauls: Because I think that it is the only way to turn left/right the robot. Do you know other way? If yes, could you tell me? Thanks
It doesn't even compile, so it is nonsense talking about it functioning.
You don't seem to understand the concept of needing to start the motor and at some time later, stop it.
Because I think that it is the only way to turn left/right the robot.
For all I know, you are using the servos for steering. I can't imagine how an electric motor would work for steering. If you are using them for some other purpose, describe that purpose.
If they are, for instance, the drive wheels, it is typically to run TWO at the same time.
They are the drive wheels but, to turn left, I move only one motor.
You don't seem to understand the concept of needing to start the motor and at some time later, stop it
I'm trying to do this, but it never works. When I have to stop the servo? I tried after the condition, but in this case the servo does not start its own.
I'm trying to do this, but it never works. When I have to stop the servo? I tried after the condition, but in this case the servo does not start its own.
Forget about millis() for now. Turn the motor on. delay() for 10 seconds. Turn the motor off. EXACTLY what happens?
Engage your brain. I mentioned that there were 4 things that needed to happen to blink an LED, and that your code did only 3 of them. It isn't rocket science to determine what the 4 are, or which your code is missing.