Let’s say I have a potentiometer hooked up to an Arduino and that also had a server plugged into. When I turn the potentiometer is would change the position of that servo instantly . Now let’s say I turn that potentiometer and it take a couple of seconds or some amount of time longer for that servo to change its position. How would I set this up without effecting the actual speed the Arduino and could I make the delay adjustable? If you know how could you give me a example on how this would be done?
If I can rephrase your question: "How can I have the arduino do several things at the same time? Read a potentiometer, wait for a certain amount of time, and do others things as well?"
There are many examples and tutorials dealing with this problem, one of them is just at the first place (sticky topic) in this section of the forum: right here. This should show you how to do it.
That's not quite what I'm looking for. I'm currently try to figure out how to set a an adjust able delay for a servo. Like you turn a potentiometer and it turns a servo. But that server reacts to that poteniometer about a couple seconds later. Its like it has a delay or a buffer that can be adjusted.
Yes, but you want to do other things during that delay don't you? At what exact moment do start the delay: when the potentiometer stops moving?
You need to read the potentiometer and compare its value to the previous one: if both are equal then you can start the timer:
declare some globals
unsigned long chrono = 0;
unsigned long myDelay = 500ul; // ms (for example)
bool delayOn = false;
then, in the loop check your potentiometer (this may be a little more complex than just comparing current and previous values)
and when you start the timer, do:
chrono = millis();
and set a boolean to true, so that you know that you need to verify if the delay has passed:
delayOn = true;
then check if your delay has passed:
if (delayOn && millis()-chrono>myDelay) {
// here your server reacts
delayOn = false;
}
The potentiometer check must be done only if the boolean is false.
This is just an example, ther may be other and better ways to do it.
The manufacturer states the speed with which the servo shaft rotates (some number of degrees per second).
You can slow that down, by commanding the shaft position incrementally, but not speed it up.
Don't try to power servos from the Arduino 5V output. Instead, use a separate power supply (e.g. 4xAA) and connect the all the grounds.
Look at how the servo is controlled in Several Things at a Time. You could use your potentiometer to change the value of servoInterval
...R
You can also use the MobaTools library.
It is a non blocking servo control library for up to 16 servos. It is compatible with arduino servo lib, but allows to control the speed of the servos.
It was written by a person active in this forum (German section).