I am attempting to create a program that would allow me to move the servo motors angle based on which of the 3 buttons are pressed. I am trying to make it so that when you press the appropriate button the motor would move either left or right based on the position of the current angle of the servomotor.
Press Button 2 while Servo is at 0 degrees, the servo will then rotate to 90 degrees
Press Button 3 while Servo is at 0 degrees, the servo will then rotate to 180 degrees
Press Button 1 while Servo is at 180 degrees, the servo will then rotate to 0 degrees
Press Button 2 while Servo is at 180 degrees, the servo will then rotate to 90 degrees, etc, etc.
I made this code based off of the robojax servo motor push button tutorial, when I tried testing it on TinkerCAD I didn't get any errors, but the servo didn't even budge a bit.
@gcjr That code has the analog pins connected to the buttons right? Also, where would the signal of the servo motor connect to if I were to utilize this code?
There may be more to it than you've told us but it seems like all you have said so far is :
if button1 pressed then write(0)
if button2 pressed then write(90)
if button3 pressed then write(180)
You don't have to worry about where the servo is now. Servos are really good at working out for themselves which way to move...if you say go to position 90 that's where they will go whether you started at 0 or 180 or somewhere else.