I should add some comments about that actually.
If you look at your code and my first example you'll see the rotateLeft() function is a blocking operation. What this means is when you call this function it will not return until the servo movement is complete. This is because you use wait() inside the for() loop to time the position changes. While thismaybe ok for a single servo, imagine you had several (think wheels on an RC car, control surfaces on a model aeroplane). In this case the blocking operation would allow you move only one servo at a time. In the case of a model aeroplane, it'll crash in more ways than one. For an RC car it's going to travel every where in circles!
What you want is a way to move multiple servos at the same time. The second example, although more complex, does this as the movement changes are done using a periodic ticker callback that looks at the "desired position" against the current position. If they differ the servos are moved _step amount closer to the desired position on each poll interval.
Using this method you can call methods on different servos one after the other and they will all work independently from one another. That's why I wrapped the servo control in a class. To abstract the servo control into a nice neat easy to use package.
[Edit] Note, I added methods to set the step and poll interval. This basically allows you to set the rates of change of the servos by changing the step amount and the poll frequency. This is just an example of how to get going. You can flesh out the class to add more or different control techniques. But hopefully will give you a good start and idea of where to go next with you project. Good luck!
Hope that helps and makes sense.
Hello,
I Want to create a generic method that receives an object of the Servo type, and then actuates on the pin defined to be the servo:
Then on int main(), I just need to create the servo object, and pass it to the method (the servo library uses is: http://mbed.org/users/jdenkers/libraries/Servo/lgfiff/docs/Servo_8h_source.html):
Is it possible that when the Servo object is passed to the method, it looses it's association to pin 21?
Thanks!