servo motor control

Hello, I am doing a project using 2 servo motors that are moving up and down in a while loop

I am making 3 different limits in 3 while loops

while(var=='3') { micro1.write(80); micro2.write(80); delay(1000); micro1.write(45); micro2.write(45); delay(1000); Serial.write('Base is displaced by 10 mm');

while(var=='2') { micro1.write(100); micro2.write(100); delay(1000); micro1.write(45); micro2.write(45); delay(1000); Serial.write('Base is displaced by 20 mm');

These is an example

I choose my limits through the serial monitor

The issue I want to switch between the variables while the servo motors are working but I can't break out the while loop to get into a new one

I would appreciate any help with that issue thank you

mafify: but I can't break out the while loop to get into a new one

Don't use WHILE. Use IF and allow loop() to do the repetition.

Have a look at the code in Several Things at a Time

...R

void loop() {
    static int limitA=90, limitB=90;
    if (Serial.available()) {
        switch (Serial.read()) {
        case '3':  limitA = 80; limitB = 45; break;
        case '2': limitA = 100; limitB = 45; break;
        }
    }
    micro1.write(limitA);
    micro2.write(limitA);
    delay(1000);
    micro1.write(limitB);
    micro2.write(limitB);
    delay(1000);
}