Ultrasonic Sensor HC-SR04 with LEDs continuously flashing

In the simulator it worked correctly.

I tested with the value 57 and then changed the division by 500 to make it easier to see.

distance = duration / 57.0;

distance = duration / 500.0;