Stepper motor, LED

I wrote the code:
Stepper motor
StepPin 9
DirPin8
LedPin13
Pot. A0,A1

// Defines pins numbers
const int stepPin = 9;
const int dirPin = 8; 
int customDelay,customDelayMapped; // Defines variables
int ledPin = 13;
int analogPin = A1;
int val = 0;
 
void setup() {
  // Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
 int ledPin = 13;
 int analogPin = A1;
 int val = 0;
digitalWrite(dirPin,HIGH); //Enables the motor to move in a particular direction
}
void loop() {
  
//  customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
// Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
  
  digitalWrite(stepPin, HIGH);  
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);
  val = analogRead(A1);
digitalWrite(ledPin, HIGH);
delay(2000);
digitalWrite(ledPin, LOW);
delay(val );
}
// Function for reading the Potentiometer
int speedUp() {
 int customDelay = analogRead(A0); // Reads the potentiometer
  int newCustom = map(customDelay, 0, 1023, 300,4000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
  return newCustom;  
}

Compile without errors, stepper motor does not turn, LED flashes without problems.
I am sorry for my English
Please, please, thank you.

This does not make sense

  digitalWrite(stepPin, HIGH); 
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);
  val = analogRead(A1);
  digitalWrite(ledPin, HIGH);
  delay(2000);
  digitalWrite(ledPin, LOW);
  delay(val );

You have the step pin HIGH for the period of customDelayMapped and then you have an interval before the next step that is the sum of customDelayMapped + 2000 + val

I suspect that is not what you intend.

Use the example in this Simple Stepper Code to get the motor working before you try anything more complex.

You have not told us what stepper motor driver you are using. Also, post a link to the datasheet for your stepper motor.

...R
Stepper Motor Basics

I use DRV8825 and stepper http://www.krokovemotory.cz/SX17-1005LQCEFds.pdf.
Separate stepper motor and LED code work. I would need a recommendation to repair the code.
Thank you.

fakfr:
I would need a recommendation to repair the code.

Did you try the code in the link I gave you?

...R

I have studied your recommendations. I thought you would write me a corrected code. If it is not, thank you for your time.

fakfr:
I thought you would write me a corrected code.

That's your job.

If, after studying my code and trying to fix your own code you are still having problems post your latest code and I will see if I can make more suggestions.

...R

I wrote this code. Experts probably find mistakes, but they do what I need.
The engine turns 1.5 sec. and shuts down according to A0. Connected LED 13 and A4899 SLEEP.

#include <Scheduler.h>

const int led = 13;
#define EnablePin 2
#define StepPin  9
#define DirectionPin 8

int ledPin = 13;
int analogPin = A0;
int val = 0;

void setup()
{
  pinMode(led, OUTPUT);

  pinMode(EnablePin, OUTPUT);
  pinMode(StepPin, OUTPUT);
  pinMode(DirectionPin, OUTPUT);
  digitalWrite(EnablePin, LOW);


  Scheduler.start(setup2, loop2);

}

void loop()
{
  digitalWrite(StepPin, HIGH); // Make a step
  delay(1); // Wait
  digitalWrite(StepPin, LOW);
  delay(3); // Wait
}
const int led2 = 13;

void setup2()
{
  pinMode(led2, OUTPUT);
}

void loop2()
{
  val = analogRead(A0);
  digitalWrite(ledPin, HIGH);
  delay(1500);
  digitalWrite(ledPin, LOW);
  delay(val * 10);
}