I can use the display as above, but it is rather difficult. I have to remember to "refresh" the digits all the time my program is running, otherwise the user will notice them flicker or even disappear. If I was serious about working this way I would ensure that whenever I am waiting for a user input (for example in the key function we wrote earlier) I call the display refresh to keep it going.

What I would really like is an automatic way of calling a "display refresh" function every now and then.

The code on the right re-arranges the original so that the refresh is taken away from the drawing action. Each time the refresh function is called it will re-draw the segment pattern for one of the digits.

Note that I am using an array to hold the actual segments which are to be displayed on the LEDs, when I want to display a pattern I load it into the array and then let the refresh take care of the rest.

/* segment patterns for our LEDs */
unsigned char
          segments [DISPLAY_SIZE] ;

The refresh function also updates the display of only one of the LEDs. It uses the variable led_counter to keep track of the LED it is to work on. If I want to update all of the LEDs I have to call the refresh function four times. If you run Exercise 4.3 you will see the same nice, solid display.