adafruit motor shield speed control manually via potentiometer

hi dear all
i ma trying to control stepper motor speed manually using potentiometer (map) instead of using the adafruit library,any help please
the adfruit cmd is motor.setSpeed(100);
but i want to use map like int Speed = analogRead(A0);
int RPM = map(Speed, 0, 1023, 0, 100);
here i attched my code

#include <AFMotor.h>
int potpin = 3;
int val;

int potpin5 = 5;
int val5;

int potpin1 = 1;
int val1;

AF_Stepper motor(48, 2);

void setup() {
//
motor.setSpeed(100); // ____ want to replace with map and potentiometer
}

void loop() {
val = analogRead(potpin);
val5 = analogRead(potpin5);
if(val > 15 )
{ motor.step(100, BACKWARD, SINGLE);
delay(0.01);
}
if(val5 > 15 )
{ motor.step(100, FORWARD, SINGLE);
delay(0.01);
}

}

thanks in advance

well you've it all lined up:

int Speed = analogRead(A0);
int RPM = map(Speed, 0, 1023, 0, 100);
motor.setSpeed(RPM);

if you do that in the setup() then it will be only read once, when you start your arduino. if you put that in the loop, then it's constantly being evaluated.

void setup() {
//
  motor.setSpeed(100); // ____ want to replace with map and potentiometer
}

So, what is the problem? You posted the necessary code to determine the appropriate speed (except that the value read from the potentiometer is not a speed and mapping it from 0 to 1023 to 0 to 100 does not produce RPM).

thank you for nice response
but i tried still not working

#include <AFMotor.h>
int potpin = 3;
int val;

int potpin5 = 5;
int val5;

int potpin1 = 1;
int val1;

AF_Stepper motor(48, 2);

void setup() {
//
int Speed = analogRead(A1);
int RPM = map(Speed, 0, 1023, 0, 100);
motor.setSpeed(RPM);
}

void loop() {
int Speed = analogRead(A1);
int RPM = map(Speed, 0, 1023, 0, 100);
motor.setSpeed(RPM);

val = analogRead(potpin);
val5 = analogRead(potpin5);
if(val > 15 )
{ motor.step(100, BACKWARD, SINGLE);
delay(0.01);
}
if(val5 > 15 )
{ motor.step(100, FORWARD, SINGLE);
delay(0.01);
}

}

it works finally but it need to reset the arduino when we chang the potentiometer

it works finally but it need to reset the arduino when we chang the potentiometer

If you moved the code to read the potentiometer and set the speed into loop(), that would not be necessary.

Nice job on the code tags. NOT!

You do have 3 potentiometers, right? one connected to A1 for the speed and one connected to A3 for the direction BACKWARD and one to A5 for the direction FORWARD?

when you create your motor instance you do AF_Stepper motor(48, 2); you do have a 48-step-per-revolution motor on channels 1 & 2, right?

Are you using a BYJ48 Stepper Motor (because that one has a 64 steps per revolution not 48 as the name could seem to imply). Settting the wrong step number per revolution when you create your motor object of course leads to wrong angular speed.

do you know what RPM your motor is capable of? 100 RPM is not super fast - less that 2 full turns per second.

Your use of delay(0.01); is wrong. delay takes a number in ms as parameter, not a float. So what you wrote is equivalent to delay(0);