help with - 2 digit 7 segment display and 2 74hc595

can you give me an example on how can I change the code to make it better?

Sure. The code works by alternately light up either the tens digit or the singles digit. Because it does so fast, to a human eye, it appears to be the case that both digits are lit.

If you for some reason cannot do so fast, your eyes will see that one digit is lit and another dim, and vice versa.

Or if they cannot be lit equally fast, you will see one digit being brighter than the other, etc.

Because of those restrictions and the code is in the loop(), you have to make sure that your loop execution is fast and equally fast under all scenarios. This can be quite difficult to achieve in most cases.

This can be resolved via the use of a timer interrupt. A timer will run constantly and in that process, can call your update / display routine periodically (say every 10ms). It runs entirely in the background and independently of your loop() execution. As such, it produces smooth display of both numbers.

1 Like