// Stepper motor on Wokwi!
#include <Stepper.h>
const int analogPin = A0;
const int stepsPerRevolution = 200;
int oldVal = 0;
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 2, 3, 4, 5);
void setup() {
myStepper.setSpeed(60); // rpm
}
void loop()
{
// Read new position
int analogVal = analogRead(analogPin)/5;
if(oldVal != analogVal){
int diff=analogVal-oldVal;
oldVal=analogVal;
myStepper.step(diff);
}
//if (analogVal > 430) { // 2.1V
// myStepper.step(stepsPerRevolution);
//} else if (analogVal < 390) { // 1.9V
// myStepper.step(-stepsPerRevolution);
//}
}