(Solved) accelstepper code for stepper with constant speed in 2 directions

OK,

Got it sorted out and to be honest the solution was easy as always.
You have to look through it. :slight_smile:

I used your sample and reworked it.

Here is the code that uses serialmonitor to send the button presses as this makes the button debounce for debugging obsolete. I hope someone can use it in the future as reference.
I used it with a L298 stepper board so AccelStepper stepper uses more and different pins as an Easy Driver board.

Thanks for the assistance and the pointers.

//This is an example of how you would control 1 stepper with constant speed and direction
// to be used if stepper need to act as DC motor and the steps to be taken are irrelevant

#include <AccelStepper.h>

int motorSpeed = 1000; 
int motorAccel = 800;
int LeftTurnUp = 0;
int RightTurnDown = 0;
int incomingByte = 0;   // for incoming serial data
int enablePin10 = 10;  // switch off coils when not in use

AccelStepper stepper(4,4,5,6,7); // set up the stepper as 4 wire bipolair on pin 4,5,6,7

void setup()
{
  Serial.begin(9600);
  
  stepper.setMaxSpeed(motorSpeed);
  stepper.setSpeed(motorSpeed);
  stepper.setAcceleration(motorAccel);
  
  pinMode(enablePin10, INPUT);

}

void loop()
{

  if (Serial.available() > 0) 
  {
    incomingByte = Serial.read();
    {
      if (incomingByte == '1')
      {
        digitalWrite(enablePin10, HIGH);
        LeftTurnUp = 1;
        RightTurnDown = 0;
      } 
      
      if (incomingByte == '2')
      {
        digitalWrite(enablePin10, HIGH);
        RightTurnDown = 1;
        LeftTurnUp = 0;
      }

      if (incomingByte == '3')
      {
        LeftTurnUp = 0;
        RightTurnDown = 0;
        stepper.moveTo(0);
        digitalWrite(enablePin10, LOW);
      } 
    }
  }

  if (LeftTurnUp == 1)  //left turn
  {
    stepper.moveTo(1000000); //move many steps - more then mechanical needed
  }

  if (RightTurnDown == 1)  //right turn
  {
    stepper.moveTo(-1000000); //move many steps - more then mechanical needed
  }

  stepper.run();
}