Sharp 2D120X, piezo speaker, park assistent

Unfortunately my sketch works contrariwise - the farther the obstacle is, the faster the piezo speeker bleeps.

Nothing in the code that toggles the speaker off or on has any relation to distance. The speaker is turned on and off a fixed number of times at fixed intervals. If you are hearing otherwise, you need to post some other code or get your hearing checked.