This in an improved version of Keeping Score with LED Counter article originally written by John O'Donnell.
I made some changes to make it more flexible and easier to follow. The function is almost identical to the existing one from John, but about 1/4 the size.
using