Ultrasonic sensor switch state??

Hi, I need some help with a project I’m doing. I’m trying to re-create a light gate measuring time but with ultrasonic sensors.

I have one sensor currently set up and I’m trying to make it work that once something goes through it, its starts to measure time, and when it goes through the second one, it stops. I can’t get the sensor to continue running the time after it reaches a certain distance.

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int trigpin = 9;
const int echopin = 10;
int LED1 = 7;

bool isRunning = false;

long duration;
int distance;

void setup() {
  pinMode(trigpin, OUTPUT);
  pinMode(echopin, INPUT);
  pinMode(LED1, OUTPUT);
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("TIMER!");
  delay(2000);
  lcd.clear();

  noInterrupts();
  interrupts();
}

double i = 0;
double a = millis();
double c ;

void loop() {
  digitalWrite(trigpin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigpin, HIGH);
  delayMicroseconds(10);

  duration = pulseIn(echopin, HIGH);
  distance = (duration * 0.034) / 2;

if (distance < 10){
    isRunning = true;
  }

  if (distance < 10 && isRunning == true) {
    distance == 10;
    c = millis();
    i = (c - a) / 1000;
    lcd.print(i);
    lcd.setCursor(7, 0);
    lcd.print("Sec's");
    lcd.setCursor(0, 0);
    Serial.println(c);
    Serial.println(a);
    Serial.println(i);
    Serial.println("......");
    delay(100);
  }
}

if someone could help it would be greatly appreciated, I haven’t touched my Arduino in quite some time, so my knowledge has dwindled.

distance == 10;Oops

this

if (distance < 10){
    isRunning = true;
  }

  if (distance < 10 && isRunning == true) {

produces this effect

if (distance < 10){

aarg:
this

if (distance < 10){

isRunning = true;
  }

if (distance < 10 && isRunning == true) {




produces this effect



if (distance < 10){

I removed that from my code. Is there a way to create a sort of state where it doesnt stop counting after the object leaves its path?