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. Commented Jan 3, 2021 at 16:41
  • What's a "double" high input? Commented Jan 4, 2021 at 16:34
  • double high input detection of the sensor Commented Jan 5, 2021 at 8:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.