Controling stepper motor with L298N and 2 limit switch

Hello,
I'm trying to control a carriage in both direction (left and right) using a limit switch (LS) à both end. Starting at the right end and go true left direction and then when the carriage hit the left LS go back to the right direction and continue that movement until the right LS is hit. Then go back to the left and continue the movement back and forth. I would like to stop it with a pushbutton who could be a pause on the movement. Then if i push back that button the movement restart. I've include the circuit, the code I found on the web and a little movie of the carriage . I need help to integrate my 2 LS, the control button and the code that would be inserted. Thanks a lot if somebody could help me.

Stepper_avec_pot_pour_vitesse.ino (1.15 KB)

Carriage Chariot.mpg (1.78 MB)

elpedro57:
I need help to integrate my 2 LS, the control button and the code that would be inserted.

Post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. And please use the code button </> when posting code
codeButton.png

...R
Stepper Motor Basics
Simple Stepper Code

I've work hard on my project and now it's fonctionnel. The carriage is running 2 times back and forth. When the carriage is moving, a infrared lamp is lighting. Instead of coding that way, I would like to control it with 2 limit switch. One at each extremity. I'm using a stepper 12 volts nema 17 motor, a L298N driver (VMA409) and a relay module to control the infrared light.

Here's my code

Thank you for the help

#include <Stepper.h>
#define button1 2
#define button2 3

//int enA = 4;  // Motor energy control
//int enB = 5;

const int STEPS_PER_REV = 1300;  // change this to fit the number of steps per revolution
                                     // for 1.8 degree step angle 200 will maximum

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(STEPS_PER_REV, 8,9,10,11);      // L298n port IA IB IC ID accordingly

void setup(){

   
pinMode(4, OUTPUT);   // Motor energy
pinMode(5, OUTPUT);   // Motor energy
pinMode(6, OUTPUT);   // Lamp relay control

   pinMode(button1, INPUT_PULLUP); // Input pulse to arduino by pressing button 1
   pinMode(button2, INPUT_PULLUP); // Input pulse to arduino by pressing button 2
  myStepper.setSpeed(5); // RPM, 60 Rotation per minute
} 


void loop() { 
  
 if (digitalRead(button1) == LOW || digitalRead(button2) == LOW) { // If no key is pressed 
 if (digitalRead(button1) == LOW && digitalRead(button2) == HIGH) { // if one is idle (L) and the other one (R) key pressed

  digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
  
  myStepper.step(STEPS_PER_REV ); // Stepper motor rotates CW (Clockwise)
  
  digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW); 
 
  delay(500); // pause time after per steps 0,5 second
  
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
  
  myStepper.step(-STEPS_PER_REV );  // Stepper motor rotates CCW (Anticlockwise)

  digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW); 
  
  delay(500); // pause time after per steps 0,5 second

  digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
  
  myStepper.step(STEPS_PER_REV ); // Stepper motor rotates CW (Clockwise)
  
  digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW); 
 
  delay(500); // pause time after per steps 0,5 second
  
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
  
  myStepper.step(-STEPS_PER_REV );  // Stepper motor rotates CCW (Anticlockwise)

  digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW); 
  
  delay(500); // pause time after per steps 0,5 second
  
 } }    }