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 http://michaelteeuw.nl/post/158404930702/the-recursive-ledcontrol-counter
void showNumber(long number, byte pos = 0) {
byte digit = number % 10;
lc.setDigit(1,pos,digit,false);
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*/
lc.shutdown(address,false);
/* Set the brightness to a medium values */
lc.setIntensity(address,8);
/* and clear the display */
lc.clearDisplay(address);
}
}
void loop() {
showNumber(num);
num ++;
if (num > 199999999) num = 0; // Filled the display so start the count over
}