1

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;
      }
    }
  }
3
  • 2
    Please edit your question to add the code there, not in an answer. The code markup is three backticks, not [code] here. Look at the help in the editor in case of doubt. – Mat Jan 3 at 16:41
  • What's a "double" high input? – Majenko Jan 4 at 16:34
  • double high input detection of the sensor – Sabri73 Jan 5 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.