Help for Programming Servo being controlled by push buttons.

Hi everyone. I am just new here in arduino stuff.
I have a small project which a servo motor being controlled by push buttons.

I have this 2 push buttons.
Button 1 -when being pressed, will turn the servo motor from 0 - 90 degrees and just stops there.
Button 2 -when being pressed, will turn the motor back from 90 - 0 degrees.

it works like something go up and down.
just like an toll gate, which it goes down and up.

Im just new here so please bare with me.
Your help will be much appreciated.
Thank you so much.
Waiting for your great response. :slight_smile:

Simple servo/button test code.

//zoomkat servo button test 12-29-2011

#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);
  }
}

If you one one switch to rotate the servo one time, you need to look at the state change detection example. You want the action to occur only when the switch transitions from the released state to the pressed state. The transition from pressed to released should do nothing.