I have a SG90 servo and I want to hook up 2 push buttons to rotate the servo, so if i press one of the push buttons, lets just say push button on the left (button1) the servo will rotate to the left, same with the other side, if i press the right pushbutton it will rotate to the right, I have written up a code which I THOUGHT would've worked, but now I regret thinking such, because the buttons do not respond to any of my presses, the code is listed below and so is my virtual wiring made on tinkerCAD (I have my setup in real life not just in TinkerCAD) Any ideas? I use a INPUT_PULLUP on both the pushbuttons for your information.
After changing the if statements to have the digitalRead, now I have another problem, it did work, the servos do respond to my commands now, but... They don't do what I want them to do, in my code it is said whenever a button is pressed it will add to int servoPos, but whenever I press a button, the servo sort of moves like a centimeter to the left, and then returns to its original position, in a matter of a second. But if I spam the button a bit, the button will turn exactly 180 degrees, any idea about this one? Thanks for your response by the way
I uploaded your code and the buttons do not work anymore, they do not move the servo even a little bit, i checked the wires and they sure are secured and connected. The servo is locked up meaning it is recieving electricity, and on the serial monitor, which i opened up, set baud to 115200 and restarted my arduino pressing the built in button, pressing the buttons or even doing nothing printed nothing on the serial monitor, I have my USB to the Arduino cable connected perfectly.