Drive of Remote Control Car

Hello all,
Sorry I’m pretty crap at explaining but… I’ve been writing some code to drive a remote control cars motors depending on the values that I input into the Analog inputs(with the remote control transmitter). It works all well, for example if i press forward it will go forward and if i press back it will go back. However, the last command I input will go on infinitely. Like if I press forward it will keep going forward when I only want it to go forward for the time in-which I press forward. I guess I’m going amiss with my delays or something?
This code is to go as part of a Collision Avoidance System

const int motor1 = 12;
const int motor2 = 9;

const int steer1 = 13;
const int steer2 = 8;

const int PWM_M = 3;


int up = 0;
int down = 0;
int left = 0;
int right = 0;

void setup()
{
  Serial.begin (9600);
  
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);

  pinMode(motor1, OUTPUT); 
  pinMode(motor2, OUTPUT); 
  pinMode(steer1, OUTPUT); 
  pinMode(steer2, OUTPUT);
  
  digitalWrite(motor1,LOW);
  digitalWrite(motor2,LOW);
  digitalWrite(steer1,LOW);
  digitalWrite(steer2,LOW);
  
}

void loop(){
left = analogRead(A0);
Serial.print("left:  ");
Serial.println(left);
right = analogRead(A1);
Serial.print("right:  ");
Serial.println(right);
down = analogRead(A3);
Serial.print("down:  ");
Serial.println(down);
up = analogRead(A2);
Serial.print("up:  ");
Serial.println(up);

if (down < 400){
  backward(1);
  }
  if (up < 400){
  forward(1);
  }
  if (left > 400){
  turnleft(1);
  }
  if (right > 400){
  turnright(1);
  }
}
void turnleft(int t){
  digitalWrite (13, HIGH);                              
  digitalWrite (8, LOW);
  digitalWrite (11, HIGH);
  delayMicroseconds(t);
} 
void turnright(int t){
  digitalWrite (8, HIGH);                              
  digitalWrite (13, LOW);
  digitalWrite (11, HIGH);
  delayMicroseconds(t);
}
void stopmotors(int t){
  digitalWrite (9, HIGH);                              
  digitalWrite (8, HIGH); 
  digitalWrite (3, HIGH);
  digitalWrite (11, HIGH);
  delayMicroseconds(t);
} 
  void forward(int t){
  digitalWrite(12, HIGH);
  digitalWrite(9, LOW);
  analogWrite(PWM_M, 120);
  delay(t);
}
void backward(int t){
  digitalWrite (9, LOW);                              
  digitalWrite (12, LOW);
  analogWrite(PWM_M, 120); 
  delay(t);
}

Remove the delays in your direction functions. Those are causing you to lock out the rest of the system while they run. I would look into Blink without Delay to see how to hand polling every some milliseconds so your car doesn't get too twitchy, but I imagine the delays are not helping. What you probably want to do is have the car update its direction commands every 100ms based on the position of the inputs, and make sure to make them all exclusive.

Also, you never call stopmotor() which is why it won't stop.

Thanks for the advice, I will look into blink without delay in the near future.
I have tried calling from the stopmotor but when I do, it doesn’t seem to like it at all. I must not be using it properly. I’m not so good with the control of the car

Something like:

  if (up < 400){
  forward(1);
  stopmotors(1);
  }