hello! so I am having a little bit of trouble, I am trying to get a button to stay on so my servo motor can stay in a position until the button is pressed again. Furthermore, I am using the servo motor to move a rack and pinion. This is all the code that I have right now
I think what you need is state detection. In other words, the code continuously monitors the button to see if it has been pressed, and each time it is pressed it changes the state (of the servo). So you press it once, the servo moves to 180. Until its pressed again, it stays at 180 because that is the stored state. This example is slightly more complex than what you need, but it will give you the idea.
hey so i tried the code and it worked, only issue is when I first start up my code, I have to click the button once before it goes to pos= 0
So, you know which line of code causes the servo to move to position 0. What do you suppose would happen if you copied that line to setup(), before you attach the servo?