// https://wokwi.com/projects/364535266637057025
// for https://forum.arduino.cc/t/stepper-motor-control-using-millis/1126030
#define dirPin 2
#define stepPin 3
void setup() {
// Declare pins as output:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
Serial.begin(115200);
}
void loop() {
int pval=analogRead(A0);
Serial.print(pval);
Serial.print(" ");
for (int i=0; i<=pval; i++) {
digitalWrite(dirPin, HIGH); //direction.
digitalWrite(stepPin, HIGH);
Serial.println(analogRead(A1));
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
delay(1000);
}