here is my code:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int buttonState = 0;
int buttonState2 = 0;
int pos = 0; // variable to store the servo position
const int buttonPin = 3;
const int buttonPin2 = 5;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
myservo.write(pos++);
delay(15); // waits 15ms for the servo to reach the position
}
else if(buttonState2 == HIGH){
myservo.write(pos--);
delay(15); // waits 15ms for the servo to reach the position
}
}
I have 2 buttons and a servo. The button on pin 3 will make the servo rotate correctly. However, I want the other button to make the servo rotate the other way, and it will not. I have tried plugging the other button into 3 and it works there. I think I must be dong something simple wrong.