Stepper motor direction

Im using this code:

#include <Stepper.h>
int current_position = 0;
const char direction_pin = 4;
const char step_pin = 5;
const char pot_pin = 0; //analog input 1
#define Limit01 7  
#define Limit02 8   
void setup()
{
pinMode(Limit01, INPUT);
pinMode(Limit02, INPUT);
pinMode(direction_pin, OUTPUT);
pinMode(step_pin, OUTPUT);
pinMode(pot_pin, INPUT);
}

void loop()
{
int  readvalue = analogRead(pot_pin);
readvalue = map(readvalue,0,1023,0,1151);
if (readvalue > current_position+20)
{
 step_motor_forward();
 current_position += 1;
}
else if (readvalue < current_position-20)
{
 step_motor_back();
 current_position -= 1;
}
}//end of loop

void step_motor_forward()
{
if (digitalRead(Limit02)) {}  
    
else {
digitalWrite(direction_pin, LOW);
digitalWrite(step_pin, HIGH);
digitalWrite(step_pin, LOW);
}
}

void step_motor_back()
{
if (digitalRead(Limit01)) {} 
    
else {
digitalWrite(direction_pin, LOW);
digitalWrite(step_pin, LOW);
digitalWrite(step_pin, HIGH);
}
}

How revers direction on stepper motor. Turn potentiometer to left motor direction left, turn potentiometer right stepper motor to left, need me to right. A4988 driver and arduino and nema 17. potentiometer is 10k.

The first thing to do is to determine whether the pot has been turned to the left or right. Start by doing that and printing a message to indicate which way the motor should turn and nothing else.


This schematich, and to A0 connected potentiometer 10k.

Don't you think that one of the two direction_pin codes need to change??
Normally in a step and direction setup direction CONTROLS the direction of the stepper.

they BOTH set direction_pin LOW:

void step_motor_forward()
  {
    if (digitalRead(Limit02)) {}  
    else {
    digitalWrite(direction_pin, LOW);  // SEE?? THIS IS SET LOW
    digitalWrite(step_pin, HIGH);
    digitalWrite(step_pin, LOW);
    }
  }

void step_motor_back()
  {
  if (digitalRead(Limit01)) {} 
  else {
    digitalWrite(direction_pin, LOW);  // THIS -ALSO- SETS 
    digitalWrite(step_pin, LOW);
    digitalWrite(step_pin, HIGH);
    }
  }

Agen motor turn to left, to another direction. Change stepper and agen test, no another direction, only left or right.

need me like this for one stepper motor and pot, with a4988 driver.

If you are using a specialized stepper driver like an A4988 do NOT use the standard stepper library as it is not intended for them. Use the AccelStepper library or just write your own code,

The examples in this Simple Stepper Code can be used for testing and for understanding how the control works.

...R
Stepper Motor Basics