DM542m&joystick and Stepper Motor

So, Hi Guys.
I am new with Arduino and i want to build a Joystick Stepmotor control. I found a Code in Internet and tryed to change it for my project. But when the sketch is running my Step Motor turns at the start, but i want that it stops when the Joystick is by 470-550 and goes forward by >550 and backward by <470.

I will be very thankful for your Help.

Here is the Sketch;

#include <Stepper.h>

const int num_step = 200;
const int pulPin = 8;
const int dirPin = 9;
const int enblPin = 10;

int loops = 0;

int Pot1 = 0;
int val;
Stepper stepper(num_step, dirPin, pulPin);

void setup() {

Serial.begin(9600);
pinMode(pulPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enblPin, OUTPUT);

digitalWrite(pulPin, LOW);
digitalWrite(dirPin, LOW);
digitalWrite(enblPin, LOW);

digitalWrite(enblPin, HIGH);
delay(100);
digitalWrite(enblPin, LOW);
}

void loop() {

int PVal=analogRead(Pot1);
if (PVal >= 470 || PVal <= 550)
{
// which command do i need here???

}
if (PVal > 550 )
{
int K= map (PVal, 551,1023,0,400); /* max is the value that you get from your experiment with the max speed of the stepper before stalling*/
int S=map (K, 0,400,0,num_step);
stepper.setSpeed(K); //this set the speed of the stepper motor
stepper.step(S); //this set the direction and the number of step it would take
Serial.print(“Forward, K=”);
Serial.print(K);
Serial.print(" PVAL=");
Serial.println(PVal);
}
if (PVal < 470 )
{
int K= map (PVal, 0,469,400,0); /* max is the value that you get from your experiment with the max speed of the stepper before stalling*/
int S=map (K, 0,400,0,num_step);
stepper.setSpeed(K); //this set the speed of the stepper motor
stepper.step(-S); //this set the direction and the number of step it would take
Serial.print(“Backward, K=”);
Serial.print(K);
Serial.print(" PVAL=");
Serial.println(PVal);

}

}

So, what does the code ACTUALLY do? Don’t you think that that might be important?

    // which command do i need here???

The one to do whatever it is you need to do.

I really suspect that you are using entirely the wrong kind of motor for your unspecified application.

On every pass through loop() (THOUSANDS of times per second), when the joystick is not centered, you are telling the stepper to step between 0 and 400 times in one direction or the other. I can not, for an instant, believe that that is the proper thing to do.

I want that my stepper Motor goes Forward when the Joystick is between 550 -1023 and go forward between 0 - 470.
Between 470 and 550 it has to Stop, but it is not stopping :confused:

I want that my stepper Motor goes Forward when the Joystick is between 550 -1023 and go forward between 0 - 470.

Get real. Stepper motors do not "go forward" (or backwards). They step. One step at a time. You can tell the motor to step more than once, and it will step that number of times.

If, as you are doing, you tell it to step (up to) 400 times, several thousands of times while the joystick is forward, then you return the joystick to the center, the stepper is going to continue stepping for a long time.