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);
}
}