try to show the record of the nearest distance through rgb

i need to the the rgb show the nearest distance i ever hit
and hold that particular color for 5 seconds
i cannot do that because as i am getting away from that object the rgb start to change according to my distance

wonder if any solution to my problem
a example of code will be great

#include "Adafruit_VL53L0X.h"
// address we will assign if dual sensor is present
#define LOX1_ADDRESS 0x30
#define LOX2_ADDRESS 0x31
// set the pins to shutdown
#define SHT_LOX1 7
#define SHT_LOX2 6
// objects for the vl53l0x
Adafruit_VL53L0X lox1 = Adafruit_VL53L0X();
Adafruit_VL53L0X lox2 = Adafruit_VL53L0X();
// this holds the measurement
VL53L0X_RangingMeasurementData_t measure1;
VL53L0X_RangingMeasurementData_t measure2;
const byte led1 = 2;
const byte led2 = 3;
const byte led3 = 4;
const byte led4 = 5;
int BluePin = 9;
int RedPin = 10;
int GreenPin = 11;
boolean ledState; // on or off
unsigned long ledTime; // when leds were turned on
unsigned long interval = 5000; // burn time
boolean printed; // for 'out of range'
int red  = 0;
int green  = 0;
int blue = 0;
/*
    Reset all sensors by setting all of their XSHUT pins low for delay(10), then set all XSHUT high to bring out of reset
    Keep sensor #1 awake by keeping XSHUT pin high
    Put all other sensors into shutdown by pulling XSHUT pins low
    Initialize sensor #1 with lox.begin(new_i2c_address) Pick any number but 0x29 and it must be under 0x7F. Going with 0x30 to 0x3F is probably OK.
    Keep sensor #1 awake, and now bring sensor #2 out of reset by setting its XSHUT pin high.
    Initialize sensor #2 with lox.begin(new_i2c_address) Pick any number but 0x29 and whatever you set the first sensor to
 */
void setID() {
  // all reset
  digitalWrite(SHT_LOX1, LOW);    
  digitalWrite(SHT_LOX2, LOW);
  delay(10);
  // all unreset
  digitalWrite(SHT_LOX1, HIGH);
  digitalWrite(SHT_LOX2, HIGH);
  delay(10);
  // activating LOX1 and reseting LOX2
  digitalWrite(SHT_LOX1, HIGH);
  digitalWrite(SHT_LOX2, LOW);
  // initing LOX1
  if(!lox1.begin(LOX1_ADDRESS)) {
    Serial.println(F("Failed to boot first VL53L0X"));
    while(1);
  }
  delay(10);
  // activating LOX2
  digitalWrite(SHT_LOX2, HIGH);
  delay(10);
  //initing LOX2
  if(!lox2.begin(LOX2_ADDRESS)) {
    Serial.println(F("Failed to boot second VL53L0X"));
    while(1);
  }
}
void read_dual_sensors() {
  
  lox1.rangingTest(&measure1, false); // pass in 'true' to get debug data printout!
  lox2.rangingTest(&measure2, false); // pass in 'true' to get debug data printout!
  // print sensor one reading
  Serial.print("1: ");
  if(measure1.RangeStatus != 4) {     // if not out of range
    Serial.print(measure1.RangeMilliMeter);
  } else {
    Serial.print("Out of range");
  }
  
  Serial.print(" ");
  // print sensor two reading
  Serial.print("2: ");
  if(measure2.RangeStatus != 4) {
    Serial.print(measure2.RangeMilliMeter);
  } else {
    Serial.print("Out of range");
  }
  
  Serial.println();
}
void setColor(int red, int green, int blue)
{
  analogWrite(RedPin, red);
  analogWrite(GreenPin, green);
  analogWrite(BluePin, blue);
}
void setup() {
  Serial.begin(115200);
  
  // wait until serial port opens for native USB devices
  
  while (! Serial) { delay(1); }
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(SHT_LOX1, OUTPUT);
  pinMode(SHT_LOX2, OUTPUT);
  Serial.println("Shutdown pins inited...");
  digitalWrite(SHT_LOX1, LOW);
  digitalWrite(SHT_LOX2, LOW);
  Serial.println("Both in reset mode...(pins are low)");
  
  
  Serial.println("Starting...");
  setID();
 
}
void loop() {
   
  read_dual_sensors();
     if (measure1.RangeMilliMeter ,measure2.RangeMilliMeter < 500 ){ {
      digitalWrite(led4, HIGH);
      setColor(255, 0, 0);//red
    };
    if (measure1.RangeMilliMeter ,measure2.RangeMilliMeter < 400 ) {

      digitalWrite(led3, HIGH);
      setColor(0, 0, 255);
    };
    if (measure1.RangeMilliMeter ,measure2.RangeMilliMeter < 300 ) {
      digitalWrite(led2, HIGH);
      setColor(80, 0, 80);// pink
    };
    if (measure1.RangeMilliMeter ,measure2.RangeMilliMeter <  200) {
      digitalWrite(led1, HIGH);
      setColor(0, 255, 0);//green
     
    };
    
    ledState = true; // remember led(s) are on
    ledTime = millis(); // note the time
    printed = false; // enable printing 'out of range'
  }
  if (ledState && millis() - ledTime > interval) { // if a led is on and time is up
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    setColor(0, 0, 0);
    ledState = false; // leds are off

  }
}

I am not sure if this will work but try this code.
Tell me if it works.

#include “Adafruit_VL53L0X.h”
// address we will assign if dual sensor is present
#define LOX1_ADDRESS 0x30
#define LOX2_ADDRESS 0x31
// set the pins to shutdown
#define SHT_LOX1 7
#define SHT_LOX2 6
// objects for the vl53l0x
Adafruit_VL53L0X lox1 = Adafruit_VL53L0X();
Adafruit_VL53L0X lox2 = Adafruit_VL53L0X();
// this holds the measurement
VL53L0X_RangingMeasurementData_t measure1;
VL53L0X_RangingMeasurementData_t measure2;
const byte led1 = 2;
const byte led2 = 3;
const byte led3 = 4;
const byte led4 = 5;
int BluePin = 9;
int RedPin = 10;
int GreenPin = 11;
boolean ledState; // on or off
unsigned long ledTime; // when leds were turned on
unsigned long interval = 5000; // burn time
boolean printed; // for ‘out of range’
int red = 0;
int green = 0;
int blue = 0;
/*
Reset all sensors by setting all of their XSHUT pins low for delay(10), then set all XSHUT high to bring out of reset
Keep sensor #1 awake by keeping XSHUT pin high
Put all other sensors into shutdown by pulling XSHUT pins low
Initialize sensor #1 with lox.begin(new_i2c_address) Pick any number but 0x29 and it must be under 0x7F. Going with 0x30 to 0x3F is probably OK.
Keep sensor #1 awake, and now bring sensor #2 out of reset by setting its XSHUT pin high.
Initialize sensor #2 with lox.begin(new_i2c_address) Pick any number but 0x29 and whatever you set the first sensor to
*/
void setID() {
// all reset
digitalWrite(SHT_LOX1, LOW);
digitalWrite(SHT_LOX2, LOW);
delay(10);
// all unreset
digitalWrite(SHT_LOX1, HIGH);
digitalWrite(SHT_LOX2, HIGH);
delay(10);
// activating LOX1 and reseting LOX2
digitalWrite(SHT_LOX1, HIGH);
digitalWrite(SHT_LOX2, LOW);
// initing LOX1
if(!lox1.begin(LOX1_ADDRESS)) {
Serial.println(F(“Failed to boot first VL53L0X”));
while(1);
}
delay(10);
// activating LOX2
digitalWrite(SHT_LOX2, HIGH);
delay(10);
//initing LOX2
if(!lox2.begin(LOX2_ADDRESS)) {
Serial.println(F(“Failed to boot second VL53L0X”));
while(1);
}
}
void read_dual_sensors() {

lox1.rangingTest(&measure1, false); // pass in ‘true’ to get debug data printout!
lox2.rangingTest(&measure2, false); // pass in ‘true’ to get debug data printout!
// print sensor one reading
Serial.print("1: ");
if(measure1.RangeStatus != 4) { // if not out of range
Serial.print(measure1.RangeMilliMeter);
} else {
Serial.print(“Out of range”);
}

Serial.print(" ");
// print sensor two reading
Serial.print("2: ");
if(measure2.RangeStatus != 4) {
Serial.print(measure2.RangeMilliMeter);
} else {
Serial.print(“Out of range”);
}

Serial.println();
}
void setColor(int red, int green, int blue)
{
analogWrite(RedPin, red);
analogWrite(GreenPin, green);
analogWrite(BluePin, blue);
}
void setup() {
Serial.begin(115200);

// wait until serial port opens for native USB devices

while (! Serial) { delay(1); }
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(SHT_LOX1, OUTPUT);
pinMode(SHT_LOX2, OUTPUT);
Serial.println(“Shutdown pins inited…”);
digitalWrite(SHT_LOX1, LOW);
digitalWrite(SHT_LOX2, LOW);
Serial.println(“Both in reset mode…(pins are low)”);

Serial.println(“Starting…”);
setID();

}
void loop() {

read_dual_sensors();
if (measure1.RangeMilliMeter ,measure2.RangeMilliMeter < 500 ){ {
digitalWrite(led4, HIGH);
setColor(255, 0, 0);//red
delay(5000);
};
if (measure1.RangeMilliMeter ,measure2.RangeMilliMeter < 400 ) {

digitalWrite(led3, HIGH);
setColor(0, 0, 255);
delay(5000);
};
if (measure1.RangeMilliMeter ,measure2.RangeMilliMeter < 300 ) {
digitalWrite(led2, HIGH);
setColor(80, 0, 80);// pink
delay(5000);
};
if (measure1.RangeMilliMeter ,measure2.RangeMilliMeter < 200) {
digitalWrite(led1, HIGH);
setColor(0, 255, 0);//green
delay(5000);

};

ledState = true; // remember led(s) are on
ledTime = millis(); // note the time
printed = false; // enable printing ‘out of range’
}
if (ledState && millis() - ledTime > interval) { // if a led is on and time is up
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
setColor(0, 0, 0);
ledState = false; // leds are off

}
}