Arduino not updating after taking in distance, very confused why it does not wor

Created a code for a distance sensor that lights up specific parts of the segment to show a number representing how far it is from the source. For example, if I put my finger 5cm away from the sensor, then the display would show "5" so on and so forth.
However, I have 2 of these displays so I have to switch between them using a transistor, and I ended up creating this code to switch fast and display the numbers within a bigger range now. So if I was to put something 10cm away from it, it would show 10 simultaneously on both segments(and it works). The problem is that with this solution, it cannot go beyond or under what it detects, so if it detected something 10cm away, it would stay like that until it was reset by pressing the button on the Arduino.essay writer

A snippet of what I done on the loop:

else if (distance == 10) {
digitalWrite(11, HIGH);
while (distance == 10) {
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);

Please do correct me on where I went wrong on this. If this cannot be fixed, then I have a button to add to a breadboard which might be able to reset and find a new distance, don't know how to do it though.
Thank you in advance

Once in the while loop do you ever update the value of distance ?

A snippet of what I done on the loop:

Posting a snippet is usually a waste of time. Please post a complete sketch

Please follow the advice on posting code given in posting code

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.