/*#include <AccelStepper.h>
 
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
#define dirPin 10
#define stepPin 11

void setup()
{  
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  stepper.setAcceleration(800);
   stepper.setMaxSpeed(10000);
   stepper.setSpeed(5000);        
}
 
void loop()
{  
   stepper.runSpeed();
  // stepper.acceleration(50);
}*/
/*#include <AccelStepper.h>
#define dirPin 10
#define stepPin 11
#define motorInterfaceType 1

// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);

void setup()
{  
stepper.setMaxSpeed(15000);
stepper.setAcceleration(100);
}
void loop()
{    
// Set the target position:
stepper.moveTo(99999999999);
// Run to target position with set speed and acceleration/deceleration:
stepper.runToPosition();
delay(1500);

}*/


const int stepPin = 11;
const int dirPin = 10; 

int customDelay,customDelayMapped; // Defines variables
 
void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  //int x = 200;
 
  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);
}
// Function for reading the Potentiometer
int speedUp() {
  int customDelay = 10; // Reads the potentiometer
  int newCustom = map(10, 0, 1023, 20,4000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
  return newCustom;  
}
A4988