Control 2 servo use push button different code

Hi Everyone,

I’m Kinda new to Arduino, and to Code, so I hope you all can help me out.

So my project use 2 servo.

  1. 1 servo automatically rotate 0 to 60 and back 60 to 0 Degree and repeat again (have on and off push button)
  2. 1 servo rotate 0 to 60 degree when first click pushbutton, and second click push button will make 60 to 0 degree.

Pls help me

Some old servo button test code to get you started. It might need to be updated.

//zoomkat servo button test 12-29-2011
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 5; //button pin, connect to ground to move servo
int press2 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(170);
  }    
  
  press2 = digitalRead(button2);
  if (press2 == LOW)
  {
    servo1.write(10);
  }
}

What have you tried so far? Can you read a pushbutton? Can you make a servo move? Post some code that at least tries to do what you want and then we will have something to help you with.

Steve