Alternative distance-meter, HC-SR04 doesn't work very well
In general the HC-SR04 is controlled using pulseIn().

When there is nothing within range for the sensor to detect it usually has to wait for pulseIn() to time out. That can take up to a second by default.  While that is happening the rest of the sketch cannot do anything.

You can reduce the timeout in the pulseIn() function, but it's still not going to be perfect - you'll still get a delay which will interrupt your LED sequences.

The ideal way will be to create a "free running" distance sensor system - use a timer to periodically start a ping, and use the Input Capture module of the ATMega to measure the time between the start and end edges of the returning pulse. Everything will happen asynchronously to the rest of your sketch then.

I am not aware of any libraries for Arduino boards, but I have one for the PIC32 based chipKIT boards that I use. It can't ever work on AVR based boards, but you can use it to see the general concepts and how things fit together.