Need help on making a servomotor move depending on button pressed

I am attempting to create a program that would allow me to move the servo motors angle based on which of the 3 buttons are pressed. I am trying to make it so that when you press the appropriate button the motor would move either left or right based on the position of the current angle of the servomotor.

For Example:
Button 1 - 0 degrees
Button 2 - 90 degrees
Button 3 - 180 degrees

Press Button 2 while Servo is at 0 degrees, the servo will then rotate to 90 degrees
Press Button 3 while Servo is at 0 degrees, the servo will then rotate to 180 degrees
Press Button 1 while Servo is at 180 degrees, the servo will then rotate to 0 degrees
Press Button 2 while Servo is at 180 degrees, the servo will then rotate to 90 degrees, etc, etc.

I made this code based off of the robojax servo motor push button tutorial, when I tried testing it on TinkerCAD I didn't get any errors, but the servo didn't even budge a bit.

Link for reference: Control Servo with Push buttons using Arduino - Robojax

I am a bit of a dunderhead when it comes to this sort of stuff so if anyone could lend me a hand in the right way to go, that would be great

Lift_Descend.ino (2.4 KB)

delay(100);

And everything stops, including you servos.

-jim lee

Let's start by formatting your code and posting it here in code tags as you should have done. See Read this before posting a programming question. Please do this in future

#include <Servo.h>
Servo myservo;

int angle = 0;
int anglestep = 10;

#define FIRST  2   // pin 2 is connected to 1st floor button
#define SECOND  3  // pin 3 is connected to 2nd floor button
#define THIRD  4  // pin 4 is connected to 3rd floor button
#define SIGNAL  10

void setup()
{
  Serial.begin(9600);
  myservo.attach(10);
  myservo.write(angle);
  Serial.println("Lift/Descend");
}

void loop()
{
  while (digitalRead(FIRST) == LOW)
  {
    if (angle > 0 && angle <= 90) //2to1
    {
      angle = angle - anglestep;
      if (angle < 0)
      {
        angle = 0;
      }
      else
      {
        myservo.write(angle);
        Serial.print("Moved to: ");
        Serial.print(angle);
        Serial.println(" degree");
      }
      delay(100);
    }
    else if (angle > 90 && angle <= 180) //3to1
    {
      angle = angle - anglestep;
      if (angle < 0)
      {
        angle = 0;
      }
      else
      {
        myservo.write(angle);
        Serial.print("Moved to: ");
        Serial.print(angle);
        Serial.println(" degree");
      }
      delay(100);
    }
    else //1on1
    {
      angle = 0;
    }
  }
  while (digitalRead(SECOND) == LOW)
  {
    if (angle > 90 && angle <= 180) //3to2
    {
      angle = angle - anglestep;
      if (angle > 90)
      {
        angle = 90;
      }
      else
      {
        myservo.write(angle);
        Serial.print("Moved to: ");
        Serial.print(angle);
        Serial.println(" degree");
      }
      delay(100);
    }
    else if (angle > 0 && angle < 90)  //1to2
    {
      angle = angle + anglestep;
      if (angle < 90)
      {
        angle = 90;
      }
      else
      {
        myservo.write(angle);
        Serial.print("Moved to: ");
        Serial.print(angle);
        Serial.println(" degree");
      }
      delay(100);
    }
    else
    {
      //2on2//
      angle = 90;
    }
  }
  while (digitalRead(THIRD) == LOW)
  {
    if (angle > 0 && angle <= 90) //1to3
    {
      angle = angle + anglestep;
      if (angle > 180)
      {
        angle = 180;
      }
      else
      {
        myservo.write(angle);
        Serial.print("Moved to: ");
        Serial.print(angle);
        Serial.println(" degree");
      }
      delay(100);
    }
    else if (angle > 90 && angle < 180)
    {
      //2to3
      angle = angle + anglestep;
      if (angle > 180)
      {
        angle = 180;
      }
      else
      {
        myservo.write(angle);
        Serial.print("Moved to: ");
        Serial.print(angle);
        Serial.println(" degree");
      }
      delay(100);
    }
    else
    {
      angle = 180;
    }
  }
}

consider

// control servo postion using 3 buttons

#if 0
# include <Servo.h>

#else   // Servo stub
struct Servo {
    void write (int ang) { Serial.println (ang); };
};

#endif

Servo myservo;

byte butPins [] = { A1, A2, A3 };
#define N_PINS sizeof(butPins)

byte butLst     [N_PINS] = {};

char s [80];

// -----------------------------------------------------------------------------
void setup (void)
{
    Serial.begin (9600);

    for (unsigned n = 0; n < N_PINS; n++)  {
        pinMode      (butPins [n], INPUT_PULLUP);
        butLst [n]  = digitalRead (butPins [n]);
    }
}

// -----------------------------------------------------------------------------
int angCurrent = 0;
int angTarget  = 0;
int angStep    = 10;

void loop (void)
{
#define NO_PRESS    -1
    byte butPressed = NO_PRESS;

    for (unsigned n = 0; n < N_PINS; n++)  {
        byte but = digitalRead (butPins [n]);

        if (butLst [n] != but)  {
            butLst [n] = but;

            if (LOW == but)  {
                butPressed = n;

                sprintf (s, " but %d pressed", butPressed);
                Serial.println (s);
            }
        }
    }

    switch (butPressed) {
    case 0:     // 1st button
        angTarget = 0;
        break;

    case 1:     // 2nd button
        angTarget = 90;
        break;

    case 2:     // 3rd button
        angTarget = 180;
        break;
    };

    if (angCurrent != angTarget)  {
        if (angCurrent < angTarget)
            angCurrent += angStep;
        else
            angCurrent -= angStep;

        myservo.write (angCurrent);
        delay (200);
    }

    delay (10);         // debounce
}

@gcjr That code has the analog pins connected to the buttons right? Also, where would the signal of the servo motor connect to if I were to utilize this code?

There may be more to it than you've told us but it seems like all you have said so far is :
if button1 pressed then write(0)
if button2 pressed then write(90)
if button3 pressed then write(180)

You don't have to worry about where the servo is now. Servos are really good at working out for themselves which way to move...if you say go to position 90 that's where they will go whether you started at 0 or 180 or somewhere else.

Steve