Basic Servo Question

Does anyone know of a basic code example to:

if (digitalRead(A0)) advance servo 5 degrees

if (digitalRead(A1)) reverse servo 5 degrees

Basically allow someone to tap the button or hold down to advance or reverse in 5 degree increments.


You should try to code this yourself using the information in the docs first. If you have trouble with the code, show us what you’ve done, and we can help you fix any problems.


Don’t assume by my question that I have not already tested many codes. I am having difficulty understanding how to command an increase or decrease of x degrees vs just commanding 90 or 180 degrees.

If you look at the example here:

It would be easy to then to tweak it to increment pos (pos+=5) or decrement pos (pos -=5) for each push button.