const int Speed = A0;
const int stepPin = 9;
int state = 0;
const int maxSpeed = 1000;
const int minSpeed = 10;
void setup() {
//Serial.begin(115200);
// Set the step and direction pins as output pins
pinMode(Speed, INPUT);
pinMode(stepPin, OUTPUT);
}
void loop()
{
int speed = analogRead(Speed);
// Map the input voltages to motor speed and direction
speed = map(speed, 0, 1023, minSpeed, maxSpeed);
if (state == 0)
{
analogWrite(stepPin, 255);
state = 1;
}
else if (state == 1)
{
digitalWrite(stepPin, LOW);
state = 0;
}
delayMicroseconds(speed);
}