Servo motor help

Hey guys im having some trouble in coding a 360 motor. In my original 180 i could easily make it stop at two distant points then return to its original point. But I wanted to change it to a 360 and now when i do it using my original code it just keeps spinning. Can anyone help me with making it stop at two points and then return to its original position? Here my code.

#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

Servo mainServo;
Servo servo1;
Servo servo2;

LiquidCrystal_I2C lcd(0x27, 16, 2);

const int selectButton = 2;
const int increaseButton = 3;
const int startButton = 4;

int selectedTime = 0; // 0 = hours, 1 = minutes, 2 = seconds
int countdownHours = 0;
int countdownMinutes = 0;
int countdownSeconds = 0;

bool lastSelectState = HIGH;
bool lastIncreaseState = HIGH;
bool lastStartState = HIGH;

int mainServoPos1 = 45;
int mainServoPos2 = 135;
int mainServoStart = 180;

void setup() {
    Serial.begin(9600);
    mainServo.attach(9);
    servo1.attach(10);
    servo2.attach(11);

    lcd.init();
    lcd.backlight();

    pinMode(selectButton, INPUT_PULLUP);
    pinMode(increaseButton, INPUT_PULLUP);
    pinMode(startButton, INPUT_PULLUP);

    // Reset servo positions
    mainServo.write(mainServoStart);
    servo1.write(0);
    servo2.write(0);
    
    displayTimeSelection();
}

void loop() {
    if (buttonPressed(selectButton, lastSelectState)) {
        selectedTime = (selectedTime + 1) % 3; // Cycles between 0, 1, 2
        displayTimeSelection();
    }

    if (buttonPressed(increaseButton, lastIncreaseState)) {
        increaseTime();
        displayTimeSelection();
    }

    if (buttonPressed(startButton, lastStartState)) {
        startCountdown();
    }
}

void increaseTime() {
    if (selectedTime == 0 && countdownHours < 23) {
        countdownHours++;
    } else if (selectedTime == 1 && countdownMinutes < 59) {
        countdownMinutes++;
    } else if (selectedTime == 2 && countdownSeconds < 59) {
        countdownSeconds++;
    }
}

void displayTimeSelection() {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Set Time:");
    lcd.setCursor(0, 1);
    
    lcd.print(selectedTime == 0 ? "*H " : "H ");
    lcd.print(countdownHours); // No leading zero
    lcd.print(":");
    lcd.print(selectedTime == 1 ? "*M " : "M ");
    lcd.print(countdownMinutes); // No leading zero
    lcd.print(":");
    lcd.print(selectedTime == 2 ? "*S " : "S ");
    lcd.print(countdownSeconds); // No leading zero
}

void startCountdown() {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Counting down...");
    
    while (countdownHours > 0 || countdownMinutes > 0 || countdownSeconds > 0) {
        lcd.setCursor(0, 1);
        printDoubleDigit(countdownHours);
        lcd.print(":");
        printDoubleDigit(countdownMinutes);
        lcd.print(":");
        printDoubleDigit(countdownSeconds);
        delay(1000);

        if (countdownSeconds > 0) {
            countdownSeconds--;
        } else if (countdownMinutes > 0) {
            countdownMinutes--;
            countdownSeconds = 59;
        } else if (countdownHours > 0) {
            countdownHours--;
            countdownMinutes = 59;
            countdownSeconds = 59;
        }
    }
    triggerServo();
}

void triggerServo() {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Dispensing...");

    // Move main servo to position 1
    mainServo.write(mainServoPos1);
    delay(2000);

    // Open and close first servo
    servo1.write(90);
    delay(1000);
    servo1.write(0);
    delay(1000);

    // Move main servo to position 2
    mainServo.write(mainServoPos2);
    delay(2000);

    // Open and close second servo
    servo2.write(90);
    delay(1000);
    servo2.write(0);
    delay(1000);

    // Reset main servo to start position
    mainServo.write(mainServoStart);
    delay(2000);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Done!");
}

bool buttonPressed(int button, bool &lastState) {
    bool buttonGotPressed = false;
    bool currentState = digitalRead(button);

    if (currentState != lastState) {  
        if (currentState == LOW) {   
            buttonGotPressed = true; 
        }
        lastState = currentState; 
        delay(50); 
    }

    return buttonGotPressed;
}

// Helper function to print numbers as two digits (01, 02, ... 09)
void printDoubleDigit(int number) {
    if (number < 10) {
        lcd.print("0");  
    }
    lcd.print(number);
}

Use servo.write(90) to stop the servo at specific point. Modify your triggerServo() function as follows:

void triggerServo() {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Dispensing...");

    // Move main servo to position 1
    mainServo.write(180); // Move forward
    delay(1000); // Adjust timing to control movement
    mainServo.write(90); // Stop
    delay(500);

    // Open and close first servo
    servo1.write(90);
    delay(1000);
    servo1.write(0);
    delay(1000);

    // Move main servo to position 2
    mainServo.write(0); // Move backward
    delay(1000); // Adjust timing to control movement
    mainServo.write(90); // Stop
    delay(500);

    // Open and close second servo
    servo2.write(90);
    delay(1000);
    servo2.write(0);
    delay(1000);

    // Reset main servo to start position
    mainServo.write(180); // Move forward
    delay(1000); 
    mainServo.write(90);  // Stop

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Done!");
}

If you are looking for some more ideas for servo motor-based projects, you can see here: Control Engineering: Surprising Applications of Servo Motors - The Engineering Projects

If you are using 360 servos with Servo.h, immediately when you servoX.attach(#); a 360 servo will go to "home/90 degrees" (understand, some 360 servos will need a value lower or higher than 90 degrees to STOP).

To "open and close" a servo (90 to 180, wait, 180 to 90), you will need to measure the time the servos take to go from one position to the next. The sequence will be: (1) start the servo360 turning, (2) then "STOP" after each measured length of time.

An example for a servo360 would be, (1) assuming from "STOP" at "90" degrees, (2) moving to "0", (3) waiting one second, (4) moving to "90" degrees:

servoX.write(135); // servo360 MEDIUM speed CounterClockWise
delay(250); // 1/4 second waiting for servo to arrive
servoX.write(90); // servo360 STOP
delay(1000); // stay open for one second
servoX.write(45); // servo360 medium speed ClockWise
delay(250); // 1/4 second for servo to arrive
servoX.write(90); // servo360 STOP

@ahsrabrifat was on the right path, but did not "stop" the 360servo after moving it "Open and close" after "position 1"