const int stepPin = 3;
const int dirPin = 2;
const int potPin = A0;
void setup() {
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int potValue = analogRead(potPin);
int speed = map(potValue, 0, 1023, 500, 100);
if (potValue < 512) {
digitalWrite(dirPin, LOW);
} else {
digitalWrite(dirPin, HIGH);
}
digitalWrite(stepPin, HIGH);
delayMicroseconds(speed);
digitalWrite(stepPin, LOW);
delayMicroseconds(speed);
Serial.print("Potentiometer Value: ");
Serial.print(potValue);
Serial.print("Speed (ms per step): ");
Serial.println(speed);
}