Frequency Measure

Wouldn't this delay entire code? then, the sensor wouldn't be able to detect an object approaching fast to the sensor.

You can probably do other things while the beep sounds. But do you want a new beep to start while the 1 s beep still sounds?