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);
delay(10);
digitalWrite(11, LOW);
one();
delay(10);
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
zero();
delay(10);
}
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