distance sensor and timing

hello
I am trying to solve this problem i have. I want an ultra sonic counter to count when the distance is less than 20 and not count until the distance is more than 20 and when it comes back to less than 20 it counts again. I i am wring the code for 8 days now and i still didn't figure it out. thanks for any help.

/*
* Ultrasonic Sensor HC-SR04 and Arduino Tutorial
*
* Crated by Dejan Nedelkovski,
* www.HowToMechatronics.com
*
*/
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)
const int trigPin = 12;
const int echoPin = 13;
long duration;
int distance;
int count;
#include <elapsedMillis.h>
elapsedMillis timeElapsed;

//////////////////////////////////////////
void setup() {
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
 /////////////////////////////////////////
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
////////////////////////////////////////////

if (distance > 20)
{ timeElapsed=0;}

if (timeElapsed > 5000 && distance < 20)
{
  count++;

while(distance<20){
  timeElapsed=0;
}
  }
    

 //////////////////////////////////////////
lcd.setCursor(0,0); 
lcd.print("count: "); 
lcd.print(count); 
delay(10);
///////////////////////////////////////////
}