#include <Servo.h>

Servo myservo;

const int button1Pin = 2;
const int button2Pin = 3;
const int button3Pin = 4;

int position = 90; 

void setup() {
  myservo.attach(9);  
  myservo.write(position);  
  pinMode(button1Pin, INPUT_PULLUP);
  pinMode(button2Pin, INPUT_PULLUP);
  pinMode(button3Pin, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(button1Pin) == LOW) {
    moveToPosition(23);
  } else if (digitalRead(button2Pin) == LOW) {
    moveToPosition(87);
  } else if (digitalRead(button3Pin) == LOW) {
    moveToPosition(123);
  }
}

void moveToPosition(int targetPosition) {
  int currentPosition = position;
  int steps = 80; 
  int stepSize = (targetPosition - currentPosition) / steps; 
  int stepDelay = 2000 / steps; 

  for (int i = 0; i < steps; i++) {
    currentPosition += stepSize;
    myservo.write(currentPosition);
    delay(stepDelay);
  }
  myservo.write(targetPosition); 
  position = targetPosition; 
}