Sending delay and analog data to Octal Latch D-Type Flip Flop

Hello all. I am trying to run two steppers motors using an H-Bridge and a D-Type Flip Flop buffer to store the data in it and send it to the motors while the Arduino is doing another task. I attatch here my ciruit and the datasheet of the flip flop (I am using the 74LS373). The code I am currently using to test the flip flop is this one:

//H-Bridge pins and buffer
#define enablePin1 10   //Need to be PWM
#define in1Pin 9
#define in2Pin 8
#define enablePin2 6  //Need to be PWM
#define in3Pin 5
#define in4Pin 4
#define speed_motor 150   // Max speed=255
#define LE 7


void setup() {

//Declare pins
  pinMode(in1Pin, OUTPUT);
  pinMode(in2Pin, OUTPUT);
  pinMode(enablePin1, OUTPUT);
  pinMode(in3Pin, OUTPUT);
  pinMode(in4Pin, OUTPUT);
  pinMode(enablePin2, OUTPUT);

//Motor speed
  analogWrite(enablePin1, speed_motor);
  analogWrite(enablePin2, speed_motor);

 //Buffer in storing data mode
  pinMode(LE, OUTPUT);
  digitalWrite(LE,LOW);
  Serial.begin(9600);
}


void loop() {
  //Send data to buffer
  Serial.println("Sending data to buffer to run");
  runMotor(in1Pin, in2Pin, false,false);
  runMotor(in3Pin, in4Pin, true,false);

  //Wait some time
  delay(7000);
  
  //Running motor
  Serial.println("Run Motor");
  digitalWrite(LE,HIGH);
  digitalWrite(LE,LOW);
  delay(2000);
  
  //Send data to buffer to stop motor
  Serial.println("Sending data to buffer to stop");
  runMotor(in1Pin, in2Pin, false,true);
  runMotor(in3Pin, in4Pin, true,true);
  delay(7000);
  //Running motor
  Serial.println("Stop Motor");
  digitalWrite(LE,HIGH);
  digitalWrite(LE,LOW);


}

void runMotor(int in1P, int in2P, boolean reverse,boolean stopmotor)
{
  if (!stopmotor){
  digitalWrite(in1P, ! reverse);
  digitalWrite(in2P, reverse);
  }
  else{
  digitalWrite(in1P, LOW);
  digitalWrite(in2P, LOW);
 }
}

I was wondering if it is possible to store the delays in the flip flop instead of making the Arduino to delay before activating the latch enable pin, and also the analog data about the speed motor.

I also have a problem with the current code since motors stop when the "Sending data to buffer to stop" message appears, while it should happen with the "Stop motor" message. All help is welcome. Thank you so much

sn74ls373_memory_buffer.pdf (1.56 MB)

Hello Mpedrosab,
The 74'373 is a transparent latch. The outputs follow
the inputs while the LE pin is high.
When the LE pin changes to low, the state of the
outputs is latched (that is held) in their present states
until the LE returns high. So any command that you
send will be acted upon while the LE pin is high.
But it seems that your code follows this correctly! I thought
I had a suggestion to help solve this, but it appears not to
be the case.
Herb

Thank you so much for your reply herbschwarz. But with this code motors start turning with the first Serial.println("Run Motor"); as they should, but stop with the Serial.println("Sending data to buffer to stop"); while it should stop with the Serial.println("Stop Motor"); message. Here it is an example

bzifyxgdwjqbm1mzyqxm.zip (963 KB)

I know this is a silly question, but why can't your Arduino control the two motors directly and do other things?

(Mine can).

...R

I am helping a friend with a school project and his teacher wants them to use this device to learn how to store data in an in-between device. I also think there is no sense in using it with two motors, but maybe the teacher wants to show easy examples to apply this technique later with a more complex circuit

I just come up with another question. Do I need to add a pull-down resistor to the LE pin (or another one) or does the flip flop have build in pull-down resistors?