Elegoo Robot Car delay function not working

Hello,
Thanks in advance for all of the help.

Im working on a project to take an Elegoo robot Car vers.1 to have independent wheel control.

Since the robot kit only comes with 1 L298N board to control 4 wheel motors, you can only control the wheels in 2 sets(2 wheels in left side and 2 wheels on right side). So I wanted to modify this to have independent wheel control. I’ve gotten another L298N board which I connected to my Mega 2560 with a sensor shield.
The L298N motor drivers are connected to the sensor shield which is connected to the Mega 2560.

I have succeded in being able to run the wheels individually, however, I cannot stop the wheels from moving once I do get them to move in my code. I want to be able to run one wheel for 1 second then stop it, move on to the next wheel and do the same thing for all wheels, however, for some reason, all of the execution codes in my void loop() wants to run at the same time causing all wheels to move at the same time rather than 1 by 1.
I’ve tried using both delay and millis() to stop all wheels from running without success and I’ve also tried to turn off the motors through switching the pins to LOW without success (the wheel would just sit there twitching as if it was receiving High and Low signals at the same time, not knowing what to do.
How do I solve this issue? Would it be due to the the Mega 2560 running 2 L298N boards at the same time?

PS: Please disregard the servo codes and the ultrasonic sensor codes as that is part of a later project.

Here is my code:

/

// Import the servo object from the servo library

#include <Servo.h> //servo library
Servo myservo0; // create servo object to control servo 0.
Servo myservo1; // create servo object to control servo 1.
int Echo0 = A4;
int Trig0 = A5;
int Echo1 = A2;
int Trig1 = A3;
int in1 = 9;
int in2 = 8;
int in3 = 7;
int in4 = 6;
// second Driver board
int in5 = 28;
int in6 = 29;
int in7 = 30;
int in8 = 31;
int ENA = 11;
int ENB = 5;
int ENA1 = 26;
int ENB1 = 32;
int ABS = 180;

// ENA and ENB are for wheel speed controls through int ABS
// the in pins are the motor drivers connected to the motors. 
//in 1,2 (pwr and gnd) control LeftFront motor/wheel (LF),  in3,4 control rightFront motor/wheel (RF), and so on for the back wheels. 

// MOVE FRONT COMMANDS

void mforward()
{
  analogWrite(ENA, ABS);
  analogWrite(ENB, ABS);
  analogWrite(ENA1, ABS);
  analogWrite(ENB1, ABS);
  digitalWrite(in1, HIGH); 
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW); 
  digitalWrite(in4, HIGH);
  digitalWrite(in5, HIGH); 
  digitalWrite(in6, LOW);
  digitalWrite(in7, LOW); 
  digitalWrite(in8, HIGH);

}

void mforwardLF()
{
  analogWrite(ENA, ABS);
  analogWrite(ENB, ABS);
  analogWrite(ENA1, ABS);
  analogWrite(ENB1, ABS);
  digitalWrite(in1, HIGH); 
  digitalWrite(in2, LOW);
  Serial.println("ForwardLF");
}

void mforwardRF()
{
  analogWrite(ENA, ABS);
  analogWrite(ENB, ABS);
  analogWrite(ENA1, ABS);
  analogWrite(ENB1, ABS);
  digitalWrite(in3, LOW); 
  digitalWrite(in4, HIGH);
  Serial.println("ForwardRF");
}

void mforwardLR()
{
  analogWrite(ENA, ABS);
  analogWrite(ENB, ABS);
  analogWrite(ENA1, ABS);
  analogWrite(ENB1, ABS);
  digitalWrite(in5, HIGH); 
  digitalWrite(in6, LOW);
  Serial.println("ForwardLR");
}

void mforwardRR()
{
  analogWrite(ENA, ABS);
  analogWrite(ENB, ABS);
  analogWrite(ENA1, ABS);
  analogWrite(ENB1, ABS);
  digitalWrite(in7, HIGH); //digital output
  digitalWrite(in8, LOW);
  Serial.println("ForwardRR");
}


//MOVE BACK COMMANDS

void mback()
{
  analogWrite(ENA, ABS);
  analogWrite(ENB, ABS);
  analogWrite(ENA1, ABS);
  analogWrite(ENB1, ABS);
  digitalWrite(in1, LOW); //digital output
  digitalWrite(in2, HIGH);
  digitalWrite(in3, LOW); //digital output
  digitalWrite(in4, HIGH);
  digitalWrite(in5, LOW); //digital output
  digitalWrite(in6, HIGH);
  digitalWrite(in7, LOW); //digital output
  digitalWrite(in8, HIGH);
  Serial.println("Back");
}

void mbackLF()
{
  analogWrite(ENA, ABS);
  analogWrite(ENB, ABS);
  analogWrite(ENA1, ABS);
  analogWrite(ENB1, ABS);
  digitalWrite(in1, LOW); //digital output
  digitalWrite(in2, HIGH);
  Serial.println("BackLF");
}

void mbackRF()
{
  analogWrite(ENA, ABS);
  analogWrite(ENB, ABS);
  analogWrite(ENA1, ABS);
  analogWrite(ENB1, ABS);
  digitalWrite(in3, LOW); //digital output
  digitalWrite(in4, HIGH);
  Serial.println("BackdRF");
}

void mbackLR()
{
  analogWrite(ENA, ABS);
  analogWrite(ENB, ABS);
  analogWrite(ENA1, ABS);
  analogWrite(ENB1, ABS);
  digitalWrite(in5, LOW); //digital output
  digitalWrite(in6, HIGH);
  Serial.println("BackLR");
}

void mbackRR()
{
  analogWrite(ENA, ABS);
  analogWrite(ENB, ABS);
  analogWrite(ENA1, ABS);
  analogWrite(ENB1, ABS);
  digitalWrite(in7, LOW); //digital output
  digitalWrite(in8, HIGH);
  Serial.println("BackRR");
}

void mstop()
{
  analogWrite(ENA, LOW);
  analogWrite(ENB, LOW);
  analogWrite(ENA1, LOW);
  analogWrite(ENB1, LOW);
  Serial.println("Stop");
}
// does not work for some reason as it runs simultaneously with the already executed code and not sequentially; which makes the robot twitch.  

void setup()
{
  myservo0.attach(3);// attach servo0 on pin 3 to servo object
  Serial.begin(9600);
  pinMode(Echo0, INPUT);
  pinMode(Trig0, OUTPUT);
  pinMode(Echo1, INPUT);
  pinMode(Trig1, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(in5, OUTPUT);
  pinMode(in6, OUTPUT);
  pinMode(in7, OUTPUT);
  pinMode(in8, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(ENA1, OUTPUT);
  pinMode(ENB1, OUTPUT);
}

// Begin System Code

void loop()
{
  myservo0.write(10);
  {

    mforwardLF();
    delay(2000);
    mforwardRF();
    delay(2000);
  }
}

Hi,
I have a question: which type of motor did you use to move the car ? Because I used 4 dc motors but it doesn't move.

JKim1594:
I have succeded in being able to run the wheels individually, however, I cannot stop the wheels from moving once I do get them to move in my code.

As far as I can see this code

void loop()
{
  myservo0.write(10);
  {

    mforwardLF();
    delay(2000);
    mforwardRF();
    delay(2000);
  }
}

tells the motors to start but never tells them to stop.

Explain exactly what this function (as an example) is intended to do and how it relates to one of your L298s

void mforwardLF()
{
  analogWrite(ENA, ABS);
  analogWrite(ENB, ABS);
  analogWrite(ENA1, ABS);
  analogWrite(ENB1, ABS);
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  Serial.println("ForwardLF");
}

It might be much easier to understand if it dealt with one section of the L298 at a time rather than, apparently, mixing them up.

...R