help with using a HC-SR04 Ping distance sensor to trigger a sequence

Hello,
I am new to using the Arduino, and need some help.
I am trying to animate a neon sign I made. The sign has 1 static light that is on all the time, and a three “frame” animation that is triggered by someone getting too close to the sign.

This is what the animation is supposed to look like:

       digitalWrite(Frame1, HIGH);
       delay(dLay);
       digitalWrite(Frame1, LOW);
       digitalWrite(Frame2, HIGH);
       delay(dLay);
       digitalWrite(Frame2, LOW);
       digitalWrite(Frame3, HIGH);
       
       delay(5000);
  
       digitalWrite(Frame3, LOW);
       digitalWrite(Frame2, HIGH);
       delay(dLay);
       digitalWrite(Frame2, LOW);
       digitalWrite(Frame1, HIGH);
       delay(dLay);
       digitalWrite(Frame1, LOW);

I am having a lot of trouble understanding how to insert the sensor into this question, as none of the examples I have been able to find really explain this to me.

I would be eternally grateful if someone were able to help me with this. I’ve been struggling to figure this out for a while but I have no idea what I am doing.
Sorry and thank you.

#define triggerpin 9
#define echopin 12

void setup(){
pinMode(triggerpin,OUTPUT);
pinMode(echopin,INPUT);

//your further setup
}

long get_distance(){
    long duration,distance;
    digitalWrite(triggerpin,LOW);
    delayMicroseconds(2);
    digitalWrite(triggerpin,HIGH);
    delayMicroseconds(10);
    digitalWrite(triggerpin,LOW);
    duration=pulseIn(echopin,HIGH);
    distance=(duration/2)/29.1;
return distance;
}

In essence you are defining the trigger pin which sends the sound out, wait a wee while, read echo pin pulse duration which is telling you the time it took for the sound to come back. Then you divide that by round trip and sound speed and you get your distance.

All of that is in the get_distance call. Now you can incorporate that in to your loop - keep calling get_distance and if the distance if in your range do what you wanted to do on that event.

Please check for mistakes in my code, I haven't tested it recently, picked it from my meager library and I am a noob as well. So a pinch of salt.

Yep skodela’s on the money there I reckon.

In loop() you do this:

void loop()
{

long get_distance();

if (distance < myThreshold)
{

   put all that stuff you posted earlier
}
}

and of course declare myThreshold earlier and give it the value you desire.