Change stepper dir according to predifined analog input value

I modified the code under DaveX´ link at posting #17, so that the code suggested to me by Wokwi (postin #16, no stepper driver) works as wished with the hardware of DaveX´ link (with stepper driver). To see what it´s like, u have to use Davex´-Wokwi-link and the hardware-setup shown therein (with an additional sensor at A0, I chose "analog Temp sensor", stops stepper at 34,2°C ), but with following code instead:

// Stepper motor on Wokwi!

#include <Stepper.h>

const int analogPin = A0;
const int stepsPerRevolution = 200*4;
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 7, 8);
const int dirPin = 7;

void setup() {
  pinMode(dirPin,OUTPUT);
  myStepper.setSpeed(4); // rpm
  Serial.begin(9600);
}

void loop()
{
  // Read new position
  int analogVal = analogRead(analogPin);

  if (analogVal > 430) { // 2.1V
    myStepper.step(-stepsPerRevolution);
    
  } else if (analogVal <  390) { // 1.9V
    myStepper.step(stepsPerRevolution);
    
  }
}

Please, don´t ask me why it works, I only know that it does :wink: To change the A0-input from the sensor at Wokwi, simply click on the sensor while script is already in action, and a slider will appear, with which you can change/slide the input-signal-value.
Thanks to you all, it has been a great help being here !!!