Change direction of stepper motor

Hi, so I'm trying to make something using a stepper and i need it to turn a certain amount of times then change direction. I've got the following code for the arduino to move in one direction but I can't figure out how to make it change direction after some turns. Any suggestions?

#define IN1  10
#define IN2  11
#define IN3  12
#define IN4  13
int Steps = 4096; //4096 or 768
int cstep = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(IN1, OUTPUT); 
  pinMode(IN2, OUTPUT); 
  pinMode(IN3, OUTPUT); 
  pinMode(IN4, OUTPUT); 
}

void loop()
{
  for(int x=0;x<Steps;x++)
  {
  step1();
  //delay(1);
  delayMicroseconds(900);
  }
  Serial.println("Boom!!");
  delay(1000);
  
}

void step1()
{
  //stepp
  switch(cstep)
  {
   case 0:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, HIGH);
   break; 
   case 1:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, HIGH);
     digitalWrite(IN4, HIGH);
   break; 
   case 2:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, HIGH);
     digitalWrite(IN4, LOW);
   break; 
   case 3:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, HIGH);
     digitalWrite(IN3, HIGH);
     digitalWrite(IN4, LOW);
   break; 
   case 4:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, HIGH);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, LOW);
   break; 
   case 5:
     digitalWrite(IN1, HIGH); 
     digitalWrite(IN2, HIGH);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, LOW);
   break; 
     case 6:
     digitalWrite(IN1, HIGH); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, LOW);
   break; 
   case 7:
     digitalWrite(IN1, HIGH); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, HIGH);
   break; 
   default:
     digitalWrite(IN1, LOW); 
     digitalWrite(IN2, LOW);
     digitalWrite(IN3, LOW);
     digitalWrite(IN4, LOW);
   break; 
  }
   
   cstep=cstep+1;
   if(cstep==8)
     {cstep=0;}
}

What have you got between the Arduino and the stepper motor?

What stepper motor have you got? Post a link to its datasheet.

...R
Stepper Motor Basics

Robin2:
What have you got between the Arduino and the stepper motor?

What stepper motor have you got? Post a link to its datasheet.

...R
Stepper Motor Basics

It's one of those cheap small ones from ebay 28BYJ-48 with ULN2003 driver

Positivefeed:
It's one of those cheap small ones from ebay 28BYJ-48 with ULN2003 driver

Sorry, I have no experience of them but there must be hundreds of Threads about them on the Forum.

...R

This tutorial seems to be quite good (only had a quick look)

the problem is that by using the commands for steppers from arduino this type of stepper gets really weak so i used this code with which it is much stronger( it's much harder to stop it from turning) that is why most of these tutorials are useless to me. if I just change the order of the 7 cases that I have to go backwards- (case7 becomes case 0, case6 becomes case 1, case5 becomes case 2 and so on) i get it to turn in the different direction but now i just dont know how to tell it to use this backward order of cases after lets say 3 turns. i hope you guys can understand what I mean

Well, you will need to change the code. If that is what you are having trouble with, why not post it in code tags? You know how to reverse it, so why not add more cases?

Add variable "direction" and change your code at the end of the switch:

cstep += direction;
if cstep > 7  cstep = 0;
if cstep < 0  cstep = 7;

direction = 1; // go forward
direction = -1; // go backward