I want to turn the servo motor 90 degrees with the first double high inputs, then I want to turn the motor 180 degrees with double high inputs, but the motor turns 180 degrees with one high input. thank you for all help
#include <Servo.h>
Servo myservo;
const int buttonPin = 8; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to
int Newbuttoncounter;
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
myservo.attach(9);
myservo.write(90);
delay(1000);
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
myservo.write(90);
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
buttonPushCounter++;
delay(500); // darbeleri alması için nefesleme.bu olmasa her darbede yüksek olur
}
if (buttonPushCounter % 2 == 0) {
myservo.write(0); //sağa döner
delay(500);
myservo.write(90);
delay(500);
Serial.println("WHITE");
Newbuttoncounter = buttonPushCounter;
}
else if (Newbuttoncounter % 2 == 0) {
myservo.write(180); //sola döner
delay(500);
myservo.write(90);
delay(500);
}
else {
lastButtonState = buttonState;
}
}
}
[code]here. Look at the help in the editor in case of doubt.