Two 28NYJ-48 motors / stepper motors and 2 leds that work with 2 push buttons

HI! i need to be able to run two stepper motors and two leds that turn on (the motors and the leds) when I press a button and it turns off when I press the same or another.
Sorry if I'm asking a lot, I'm a beginner in this and I don't know much.

This is what I've using so far:


#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor


// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 11, 10, 9, 8);
Stepper myStepper2(stepsPerRevolution, 7, 6, 5, 4);


int stepCount = 0;  // number of steps the motor has taken

const int ledPin1 = 2; // Pin para la primera luz LED
const int ledPin2 = 3; // Pin para la segunda luz LED

void setup() {

  // Inicializa los pines de las luces LED como salidas
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);

  // Enciende las luces LED al inicio
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin2, HIGH);
}

void loop() {
  // read the sensor value:
  int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  // set the motor speed:
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    myStepper2.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 100);
    myStepper2.step(stepsPerRevolution / 100);
  }
}

That code doesn't refer to any button but to a sensor (we don't know which one), that's hardly the code with which you try to do what you intend.
There are hundreds (if not thousands) of examples on the internet of push-button motor operation, start there.

Regards

I know there is no code that refers to a button, that's why I'm asking for help.
I've traid many many examples from the internet, I've been trying to make it work for a whole week, but I´haven't succeeded.

What Arduino board?

Please post a schematic and a more detailed description of what the buttons, LEDs and stepper motors should do.

The Stepper library step() function blocks so any commanded motion must compete before anything else can happen. Libraries like the MobaTools stepper library does has non-blocking motion functions.

Here is an example that uses a pushbutton switch to toggle a stepper on and off. You should be able to extend this to 2 motors. This uses the MobaTools stepper library to control the stepper. It uses the state change detection method to read the switch and toggle the stepper mode.

#include <MobaTools.h>

// stepper pins
const byte pin1 = 10;
const byte pin2 = 11;
const byte pin3 = 12;
const byte pin4 = 13;

const byte buttonPin = 8;
const byte ledPin = 9;

const unsigned int motorStepsPerRev = 2048;

MoToStepper xStepper(motorStepsPerRev, FULLSTEP);

void setup()
{
   Serial.begin(115200);
   Serial.println("Stepper conrol with the MobaTools stepper library");
   Serial.println("button toggles stepper on off");

   pinMode(buttonPin, INPUT_PULLUP);
   pinMode(ledPin, OUTPUT);

   xStepper.attach(pin1, pin2, pin3, pin4);
   xStepper.setSpeed(120); // rpm /10
   xStepper.setRampLen(20);
   xStepper.setZero();

}

void loop()
{
   static bool lastButtonState = HIGH; // button history
   static bool stepperMode = false; // stepper on/off mode
   static unsigned long timer = 0;
   unsigned long interval = 30;
   if (millis() - timer >= interval)
   {
      timer = millis();
      bool buttonState = digitalRead(buttonPin); // get button state
      if (buttonState != lastButtonState) // has it changed
      {
         if (buttonState == LOW) // has it been pressed
         {
            stepperMode = !stepperMode; // toggle stepper on-off
         }
         lastButtonState = buttonState; // remeber for next time
      }
      if (stepperMode == LOW) // turn steppe and LED on
      {
         xStepper.rotate(1);
         digitalWrite(ledPin, HIGH);         
      }
      else // turn stepper and LED off
      {
         xStepper.rotate(0);
         digitalWrite(ledPin, LOW);          
      }
   }
}

Sorry i'm not a good explanation for this, the truth is I don't know much about the subject, it is a job that was given in a short time and without much explanation, I would only like that once the battery is connected when the button is pressed the whole system (motors and lights) turns off and then when you press it again it turns on. This is the closest thing I managed to schematize to my circuit.