Controlling Servo Motor by a Potentiometer

I want to control the speed of my servo motor with a potentiometer put the problem is when I rotate the potentiometer, the servo motor does not respond simultaneously, yet it needs to go back again with an new cycle at its ZERO to respond to the change of the new value of speed as on the video attached on this link:

However, I want to apply the new value from the potentiometer immediately!

#include <Servo.h>

Servo servo1;
int pos1 = 0;


void setup() {
  // put your setup code here, to run once:

servo1.attach(9);
int A0 = INPUT;

}

void loop() {
  // put your main code here, to run repeatedly:
int pot = analogRead(A0);
int scale = map(pot, 0 , 1023, 1, 110);

for(pos1 = 0; pos1 < 180 ; pos1 +=1) {
  servo1.write(pos1);
  delay(scale);
}

for(pos1 = 180; pos1 >=1; pos1 -=1){
servo1.write(pos1);
delay(scale);
}
}
#include <Servo.h>

Servo servo1;
int pos1 = 0;


void setup() {
  // put your setup code here, to run once:

servo1.attach(9);
int A0 = INPUT;

}

void loop() {
  // put your main code here, to run repeatedly:
for(pos1 = 0; pos1 < 180 ; pos1 +=1) {
  servo1.write(pos1);
int pot = analogRead(A0);
int scale = map(pot, 0 , 1023, 1, 110);
  delay(scale);
}

for(pos1 = 180; pos1 >=1; pos1 -=1){
servo1.write(pos1);
int pot = analogRead(A0);
int scale = map(pot, 0 , 1023, 1, 110);
delay(scale);
}
}

If you want it respond to changes while it is in the middle of for loop moves then you will have to do the analogRead and map inside the for loops.

Steve

int A0 = INPUT;

What?

From the code you posted and your question I conclude that you have almost no idea what the code does.

try the following code to analyse the function of the program
After uploading open the serial monitor and adjust baud to value 115200

#include <Servo.h>

Servo servo1;
int pos1 = 0;


void setup() {
  Serial.begin(115200);
  Serial.println();
  servo1.attach(9);
  int A0 = INPUT;
}

void loop() {
  // put your main code here, to run repeatedly:
  int pot = analogRead(A0);
  int scale = map(pot, 0 , 1023, 1, 110);

  Serial.print("scale has value:");
  Serial.println(scale);

  for (pos1 = 0; pos1 < 180 ; pos1 += 1) {
    Serial.print("set servo to pos:");
    Serial.println(pos1);
    servo1.write(pos1);
    
    Serial.print("wait for ");
    Serial.print(scale);
    Serial.print(" milliseconds");
    delay(scale);
  }

  for (pos1 = 180; pos1 >= 1; pos1 -= 1) {
    Serial.print("set servo to pos:");
    Serial.println(pos1);
    servo1.write(pos1);
    
    Serial.print("wait for ");
    Serial.print(scale);
    Serial.print(" milliseconds");
    delay(scale);
  }
}

This forum is about improving your programming-skills. It is not about delivering ready to use solutions.
best regards Stefan

What exactly do you want controlled servo motor by potentiometer?

You can refer to these example: