Servo position

I have servos moving into a series of positions. They are set to a button push. What I want to know is, how do I get the servos to their original position at tHe end of the cycle? I feel that copy and pasting the 1st position to the end of the cycle may be inefficient.

Bstanko6: I feel that copy and pasting the 1st position to the end of the cycle may be inefficient.

You mean that if you have this:

myServo.write(33); // initialise to wherever say 33
// followed by a whole bunch of button stuff which basically does:
myServo.write(27);
myServo.write(83);
myServo.write(13);

.... you think it's wrong to put this on the end?

myServo.write(33); // return to initial pos

You have not given much detail about your problem so this answer is guesswork.

If the servo angle increase (perhaps by 10 degrees) with every button press then your code could change the value back to the start value when it exceeds the maximum value.

...R

Sorry guys, writing from the Ipad. It stinks o write on. Jimbo, basically yes, I typed out each indvidual position with delay(1000); Its a robot arm, i want the arm to go back to the original position at the end of the cycle. I have learned that copy and past is usually a sign of bad code. Or is that the only way to do this?

So don't copy and paste, type it fresh...... :P

I really can't see any other way of doing it: if you need it to finish at pos = x then you have to do a myServo.write(x) I think.

Don't copy and paste, just write one function called "home()" and call it at the start, and at the end.

AWOL: Don't copy and paste, just write one function called "home()" and call it at the start, and at the end.

.... but don't copy / paste the home() at the end, type it fresh :relaxed:

Whoa! What just happened? Are we in a temperal loop? :)

I checked reference but could not find home(). Is there an example I could get as to where I place it and how to use it?

I checked reference but could not find home()

That's because you have to write it. (test it, debug it)

just write one function called "home()" and call it at the start, and at the end.

As I wrote earlier.

AWOL:

I checked reference but could not find home()

That's because you have to write it. (test it, debug it)

Have a look here