Cascading 16 digit counter using 2 x max7219

I am trying to build a counter that counts higher than 8 digits. One of the examples from the LedControl library has a good counter, but I can't get it to carry-over into a second 7219 when it gets to 99999999. The modules I'm using are an 8-digit 7-segment led display with a max7219 controlling them, on an Uno. The modules are daisy-chained correctly and I can address either one, and have the counter work, but it won't run the number on to the second unit when the digits go higher than eight. If anyone has any ideas about doing this, I would be extremely grateful.

MAX7219 8-digit 7-segment LED test

#include "LedControl.h"

 pin 12 is connected to the DataIn 
 pin 11 is connected to the CLK 
 pin 10 is connected to LOAD

LedControl lc=LedControl(12,11,10,2); // Output pins and No. of modules

unsigned long delaytime = 500;  // delay between character updates
long num = 1234567890;          // Starting number for testing

// This routine displays a up-counter.  This utilizes a clever technique using recursion by
// Michael Teeuw
void showNumber(long number, byte pos = 0) {
    byte digit = number % 10;
    long remainingDigits = number / 10;
    if (remainingDigits > 0) {
        showNumber(remainingDigits, pos + 1);

void setup() {
  //we have already set the number of devices when we created the LedControl
  int devices=lc.getDeviceCount();
  //we have to init all devices in a loop
  for(int address=0;address<devices;address++) {
    /*The MAX72XX is in power-saving mode on startup*/
    /* Set the brightness to a medium values */
    /* and clear the display */

void loop() { 
  num ++;
  if (num > 199999999) num = 0;  // Filled the display so start the count over

your showNumber only uses module 1. so it will never use the other module.
you could try a pos %8 instead of the hardcoded 1
1 - pos % 8
depending on the order of your modules.

Additionally you can have a look at my adopted library, which should be able to print among several modules using a "standard" lc.print

1 Like

Thanks noiasca, I will try your suggestion and library when I get home from work today. Many thanks.

noiasca, I tried the modulo 8 as you suggested, and got these results. It seemed to have the effect of offsetting every digit's position by the value given. The last pic is % 2 and as you can see, every 2nd position is displayed.

I will check out your modified library next.

pos % 8

1 - pos % 8

pos % 2

That isn't quite what was meant.

lc.setDigit(pos / 8, pos % 8, digit, false);
1 Like

PaulRB, many thanks my friend. It now works. The final line to get the digits in order and cascading to the next module is..

lc.setDigit(1 - pos / 8, pos % 8, digit, false);

Very grateful to both you guys. Hopefully this thread may help someone else out one day.

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