Apologies, I originally posted under the wrong topic.
Here is what I got so far:
#include <Servo.h>
const int buttonPin1 = 10;
const int buttonPin2 = 8;
int buttonState1 = 0; //current state of button
int buttonState2 = 0; //current state of button
int buttonPushCounter1 = 0; //counter for the number of button presses
int buttonPushCounter2 = 0; //counter for the number of button presses
int lastButtonState1 = 0; //previous state of button
int lastButtonState2 = 0; //previous state of button
Servo myservo;
int pos = 0;
int directionState = 0;
void setup() {
Serial.begin(9600);
myservo.attach(9);
myservo.write(180); //Starting position is 160 degrees
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2,INPUT);
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
//something to set buttonPushcount2 to count up one, unless buttonPushCount1 is pressed in which case count down one
if (buttonState2 != lastButtonState2) {
if (buttonState2 == HIGH) {
//lastpos = pos;
directionState = 0; //direction of servo is anitclockwise
buttonPushCounter2++;
Serial.println("on");
Serial.print("position: ");
Serial.println(buttonPushCounter2);
myservo.read();
myservo.write(+35); // move anticlockwise by 35 degrees from last position
delay(60);
}
else {
Serial.println("off");
}
delay(50);
}
if (buttonState1 != lastButtonState1) {
if (buttonState1 == HIGH) {
//lastpos = pos;
directionState = 1; //direction of servo is clockwise
buttonPushCounter2--;
Serial.println("on");
Serial.print("position: ");
Serial.println(buttonPushCounter1);
myservo.read();
myservo.write(-35); // move clockwise by 35 degrees from last position
delay(60);
}
else {
Serial.println("off");
}
delay(50);
}
}