Stepper Motor and Delay to control Speed HELP

Hi guys, I quite new in ARduino, but I'm working on a Motorized Slider with arduino to shoot some videos, but now that i have the Potenstiometer I'm stuck in this code; here is my hardware setup:

with a code like this the motor goes perfectly with the standard delayLenght of 30:

int delaylegnth = 30;

void setup() {
  
  //establish motor direction toggle pins
  pinMode(12, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards???
  pinMode(13, OUTPUT); //CH B -- HIGH = forwards and LOW = backwards???
  
  //establish motor brake pins
  pinMode(9, OUTPUT); //brake (disable) CH A
  pinMode(8, OUTPUT); //brake (disable) CH B


  
  
}

void loop(){
 
  digitalWrite(9, LOW);  //ENABLE CH A
  digitalWrite(8, HIGH); //DISABLE CH B

  digitalWrite(12, HIGH);   //Sets direction of CH A
  analogWrite(3, 255);   //Moves CH A
  
  delay(delaylegnth);
  
  digitalWrite(9, HIGH);  //DISABLE CH A
  digitalWrite(8, LOW); //ENABLE CH B

  digitalWrite(13, LOW);   //Sets direction of CH B
  analogWrite(11, 255);   //Moves CH B
  
  delay(delaylegnth);
  
  digitalWrite(9, LOW);  //ENABLE CH A
  digitalWrite(8, HIGH); //DISABLE CH B

  digitalWrite(12, LOW);   //Sets direction of CH A
  analogWrite(3, 255);   //Moves CH A
  
  delay(delaylegnth);
    
  digitalWrite(9, HIGH);  //DISABLE CH A
  digitalWrite(8, LOW); //ENABLE CH B

  digitalWrite(13, HIGH);   //Sets direction of CH B
  analogWrite(11, 255);   //Moves CH B
  
  delay(delaylegnth);

}

so I tried to add 2 Potentiometer, one to set the speed with delayLenght, and the other to set the direction of rotation.
as you can see from the code, I want to take the value from pot in A3 and divide the value by 30 to set a better delay. prendo il valore e lo divido per 30 perchè ho bisogno di una tolleranza nel scegliere il delay.
The other Pot in A2 set the direction, in fact if it is <= di 513 it makes run the code that spin CCW if it's > CW.

HERE IS MY CODE:

int analogPin = 3; //collego il potenziometro della velocità a pin A3
int analogPin2 = 2; //collegoil potenziometro della direzione a pin A2
int analread = analogRead(analogPin/30);
int analread2 = analogRead(analogPin2);
int delaylegnth = analread;
int rotazione = analread2;


void setup() {
  
  //establish motor direction toggle pins
  pinMode(12, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards???
  pinMode(13, OUTPUT); //CH B -- HIGH = forwards and LOW = backwards???
  
  //establish motor brake pins
  pinMode(9, OUTPUT); //brake (disable) CH A
  pinMode(8, OUTPUT); //brake (disable) CH B
    


  //sketch completato SLIDER MOTORIZZATO arduino
  
}

void loop(){
  
  
  if (rotazione <= 511)  // va a dx se rotazione ==100
  {
 
  digitalWrite(9, LOW);  //ENABLE CH A
  digitalWrite(8, HIGH); //DISABLE CH B

  digitalWrite(12, HIGH);   //Sets direction of CH A
  analogWrite(3, 255);   //Moves CH A
  
  delay(delaylegnth);
  
  digitalWrite(9, HIGH);  //DISABLE CH A
  digitalWrite(8, LOW); //ENABLE CH B

  digitalWrite(13, LOW);   //Sets direction of CH B
  analogWrite(11, 255);   //Moves CH B
  
  delay(delaylegnth);
  
  digitalWrite(9, LOW);  //ENABLE CH A
  digitalWrite(8, HIGH); //DISABLE CH B

  digitalWrite(12, LOW);   //Sets direction of CH A
  analogWrite(3, 255);   //Moves CH A
  
  delay(delaylegnth);
    
  digitalWrite(9, HIGH);  //DISABLE CH A
  digitalWrite(8, LOW); //ENABLE CH B

  digitalWrite(13, HIGH);   //Sets direction of CH B
  analogWrite(11, 255);   //Moves CH B
  
  delay(delaylegnth);
  }
 
   if (rotazione > 511)  // va a sx se rotazione ==0
  {
    digitalWrite(9, LOW);  //ENABLE CH A
  digitalWrite(8, HIGH); //DISABLE CH B

  digitalWrite(12, HIGH);   //Sets direction of CH A
  analogWrite(3, 255);   //Moves CH A
  
  delay(delaylegnth);
  
  digitalWrite(9, HIGH);  //DISABLE CH A
  digitalWrite(8, LOW); //ENABLE CH B

  digitalWrite(13, HIGH);   //Sets direction of CH B
  analogWrite(11, 255);   //Moves CH B
  
  delay(delaylegnth);
  
  digitalWrite(9, LOW);  //ENABLE CH A
  digitalWrite(8, HIGH); //DISABLE CH B

  digitalWrite(12, LOW);   //Sets direction of CH A
  analogWrite(3, 255);   //Moves CH A
  
  delay(delaylegnth);
    
  digitalWrite(9, HIGH);  //DISABLE CH A
  digitalWrite(8, LOW); //ENABLE CH B

  digitalWrite(13, LOW);   //Sets direction of CH B
  analogWrite(11, 255);   //Moves CH B
  
  delay(delaylegnth);
 }

}

If I connect everything as it should all the leds of Motorshield stay ON and the motor makes a whistle.
If I turn o disconnect the pot nothing happend.
Please Help me

int analogPin = 3; //collego il potenziometro della velocità a pin A3
int analogPin2 = 2; //collegoil potenziometro della direzione a pin A2
int analread = analogRead(analogPin/30);  // THIS WILL READ PIN A0 since 3/30 == 0
int analread2 = analogRead(analogPin2);
int delaylegnth = analread;
int rotazione = analread2;

You can't just read the analog input once and expect moving the knob to do anything. You have to do an analogRead() every time you want to know if the knob has moved, usually t the beginning of loop():

void loop() {
    delaylenght = map(analogRead(analogPin), 0, 1023, 10, 40);  // Map the knob to a range of delays from fast (10) to slow (40)
    rotazione = analogRead(analogPin2);
.
.
.

Reading the potentiometer setting outside of a function is useless. Read the values in loop().

int analread = analogRead(analogPin/30);

Dividing the pin number by 30 was plain stupid.

I cannot realize crarly wht you mean, can you post the code as it should be?
Thank you

Those small 9v batteries can't produce enough current to drive a stepper motor.

Why not use the AccelStepper library which takes care of all the details of producing pulses for the motor.

int analread = analogRead(analogPin/30);This code divides the pin number by 30. Perhaps you meant int analread = analogRead(analogPin)/30;

English speakers might be amused by your choice of variable name.

...R

I'm glad I'm not the only one who noticed.