Servo Motors

I am trying to program a servo motor in a true/ false statement o that when a button is pressed, the servo motor will rotate. I really have no idea how to do that, or even if I should be using a case structure at all. Where do I start?


What you desire to have happen probably needs better definition.

Here is an example of pressing and holding a button to move a servo.
When the button is released the servo returns to a preset position.

If you want the button to move the servo permanently to a position, then a simple case statement might do it.

It may be better defined as a timed system, but with no timer involved. I want the button to tel th servo to rotate 180 degrees and then return to the origional angle, but without having to hold the button down. do not know if that is even possible.

That would have to be a timed action.
There is no sensor feedback built in to the servo that your code can call to check to see when the servo reaches the 180 degree mark.
All your code knows is that it ordered a turn to 180 degrees, not whether the servo arrives there or not.

You’d have to add a potentiometer that your code could read from for feedback.

How would I write the code for a timer, and then wire it into my code for the servo, in that case?

You have a couple of options.

Here is one that works only in Periodic, but is pretty straight forward:

If you want it in, then you have to set a timer and check it each time through Teleop to act when the timer expires.