user1090: I have this code for a DC motor (using this library)

#include <Arduino.h>
#include <Vnh2sp30.h>

//              ENA A   B   PWM   CS    inv
Vnh2sp30  mtrL( A0, 7,  8,  5,    A2,   0);             

void setup() {                          
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0)   {
    String first  = Serial.readStringUntil(',');
    Serial.read(); 
    String second = Serial.readStringUntil(','); 
    Serial.read();
    String third = Serial.readStringUntil(','); 
    Serial.read();
    String echo = Serial.readString();
    Serial.println(echo);
       if(first == "start"){
                Serial.println("Starting DC motor");
                int duration = atoi(second.c_str());
                int power = atoi(third.c_str());
                int starttime = millis();
                int endtime = starttime;
                while ((endtime - starttime) <= duration) // mS
                {
                  endtime = millis();
                  mtrL.run(1023);
                }
                mtrL.stop();
                Serial.println("DONE");
       }
   }
}

Then I have this code to drive multiple stepper motors (using this library):
#include "BasicStepperDriver.h"

int incomingByte = 0;   // for incoming serial data
String readString = "";

void setup() {
    Serial.begin(9600);
    motors.begin();
}

void loop() {
    if (Serial.available() > 0) {
    String first  = Serial.readStringUntil(','); // start
    Serial.read(); 
    String second = Serial.readStringUntil(','); // motor number
    Serial.read();
    String third = Serial.readStringUntil(','); // motor steps
    Serial.read();
    String fourth = Serial.readStringUntil(','); // duration (millisec)
    Serial.read();
    String fifth = Serial.readStringUntil(','); // deg
                if(first == "start") {
                  if(second == "ALL") {
                    Serial.println("Starting stepper motor ALL");
                    int steps = atoi(third.c_str());
                    int duration = atoi(fourth.c_str());
                    int deg = atoi(fifth.c_str());

                    BasicStepperDriver stepper1(steps, DIR, STEP, ENBL);
                    stepper1.enable();
                    stepper1.setMicrostep(MICROSTEPS);
                    stepper1.setRPM(MAX_RPM);

                    BasicStepperDriver stepper2(steps, DIR_2, STEP_2, ENBL_2);
                    stepper2.enable();
                    stepper2.setMicrostep(MICROSTEPS);
                    stepper2.setRPM(MAX_RPM);

                    BasicStepperDriver stepper3(steps, DIR_3, STEP_3, ENBL_3);
                    stepper3.enable();
                    stepper3.setMicrostep(MICROSTEPS);
                    stepper3.setRPM(MAX_RPM);

                    BasicStepperDriver stepper4(steps, DIR_4, STEP_4, ENBL_4);
                    stepper4.enable();
                    stepper4.setMicrostep(MICROSTEPS);
                    stepper4.setRPM(MAX_RPM);

                    int starttime = millis();
                    int endtime = starttime;
                    while ((endtime - starttime) <= duration) // mS
                    {
                      stepper1.rotate(deg);  
                      stepper2.rotate(deg);  
                      stepper3.rotate(deg);
                      stepper4.rotate(deg);
                      endtime = millis();
                    }
                    stepper1.disable();
                    stepper2.disable();
                    stepper3.disable();
                    stepper4.disable();
                    Serial.println("DONE");
                  }
                }
        }
}

My goal is to merge this two codes together and still be able to run both the DC motor and one (or all) the stepper motors all together simultaneously. The first code is running on Arduino UNO and the other code runs on Arduino MEGA board and has been tested to work. The goal is to migrate the code from Arduino UNO to the MEGA board. Driving the motor for a specific time will block Arduino from executing the Stepper motors and vice versa with the DC motor. What can be done with these codes to make sure it can run the DC motor and Stepper motors at the same time? 

user4169: Use the AccelStepper library along with the Adafruit MotorShield library
https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/install-software

1090: <p>I have this code for a DC motor (using <a href="https://github.com/OliviliK/Arduino-Robot/blob/master/libraries/Vnh2sp30/Vnh2sp30.h" rel="nofollow noreferrer">this</a> library)
</p>

<pre class="lang-cpp prettyprint-override"><code>#include &lt;Arduino.h&gt;
#include &lt;Vnh2sp30.h&gt;

//              ENA A   B   PWM   CS    inv
Vnh2sp30  mtrL( A0, 7,  8,  5,    A2,   0);             

void setup() {                          
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() &gt; 0)   {
    String first  = Serial.readStringUntil(',');
    Serial.read(); 
    String second = Serial.readStringUntil(','); 
    Serial.read();
    String third = Serial.readStringUntil(','); 
    Serial.read();
    String echo = Serial.readString();
    Serial.println(echo);
       if(first == "start"){
                Serial.println("Starting DC motor");
                int duration = atoi(second.c_str());
                int power = atoi(third.c_str());
                int starttime = millis();
                int endtime = starttime;
                while ((endtime - starttime) &lt;= duration) // mS
                {
                  endtime = millis();
                  mtrL.run(1023);
                }
                mtrL.stop();
                Serial.println("DONE");
       }
   }
}
</code></pre>

<p>Then I have this code to drive multiple stepper motors (using <a href="https://github.com/laurb9/StepperDriver/blob/master/src/BasicStepperDriver.h" rel="nofollow noreferrer">this</a> library):</p>

<pre class="lang-cpp prettyprint-override"><code>#include "BasicStepperDriver.h"

int incomingByte = 0;   // for incoming serial data
String readString = "";

void setup() {
    Serial.begin(9600);
    motors.begin();
}

void loop() {
    if (Serial.available() &gt; 0) {
    String first  = Serial.readStringUntil(','); // start
    Serial.read(); 
    String second = Serial.readStringUntil(','); // motor number
    Serial.read();
    String third = Serial.readStringUntil(','); // motor steps
    Serial.read();
    String fourth = Serial.readStringUntil(','); // duration (millisec)
    Serial.read();
    String fifth = Serial.readStringUntil(','); // deg
                if(first == "start") {
                  if(second == "ALL") {
                    Serial.println("Starting stepper motor ALL");
                    int steps = atoi(third.c_str());
                    int duration = atoi(fourth.c_str());
                    int deg = atoi(fifth.c_str());

                    BasicStepperDriver stepper1(steps, DIR, STEP, ENBL);
                    stepper1.enable();
                    stepper1.setMicrostep(MICROSTEPS);
                    stepper1.setRPM(MAX_RPM);

                    BasicStepperDriver stepper2(steps, DIR_2, STEP_2, ENBL_2);
                    stepper2.enable();
                    stepper2.setMicrostep(MICROSTEPS);
                    stepper2.setRPM(MAX_RPM);

                    BasicStepperDriver stepper3(steps, DIR_3, STEP_3, ENBL_3);
                    stepper3.enable();
                    stepper3.setMicrostep(MICROSTEPS);
                    stepper3.setRPM(MAX_RPM);

                    BasicStepperDriver stepper4(steps, DIR_4, STEP_4, ENBL_4);
                    stepper4.enable();
                    stepper4.setMicrostep(MICROSTEPS);
                    stepper4.setRPM(MAX_RPM);

                    int starttime = millis();
                    int endtime = starttime;
                    while ((endtime - starttime) &lt;= duration) // mS
                    {
                      stepper1.rotate(deg);  
                      stepper2.rotate(deg);  
                      stepper3.rotate(deg);
                      stepper4.rotate(deg);
                      endtime = millis();
                    }
                    stepper1.disable();
                    stepper2.disable();
                    stepper3.disable();
                    stepper4.disable();
                    Serial.println("DONE");
                  }
                }
        }
}
</code></pre>

<p>My goal is to merge this two codes together and still be able to run both the DC motor and one (or all) the stepper motors all together simultaneously. The first code is running on Arduino UNO and the other code runs on Arduino MEGA board and has been tested to work. The goal is to migrate the code from Arduino UNO to the MEGA board. Driving the motor for a specific time will block Arduino from executing the Stepper motors and vice versa with the DC motor. What can be done with these codes to make sure it can run the DC motor and Stepper motors at the same time? </p>
 4169: <p>Use the AccelStepper library along with the Adafruit MotorShield library</p>

<p><a href="https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/install-software" rel="nofollow noreferrer">https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/install-software</a></p>
