Attached is a new "library" for the 7-segment/LED displays based on the TM1638 controller.
These displays can be had for cheap on eBay etc.
The attachment is not a "library" in the usual sense. To make it work you'll have to edit the TM1638.h header file and configure which pins to use in that file. No run-time pin configuration is available to keep the library compact and fast.
The library uses direct port access to dramatically speed up the display/button access and to keep the compiled size small. It also uses a font stored in PROGMEM to keep SRAM usage down.
There is an existing library for the TM16xx based displays, that is easier to use, available here:
Then why use the attached library?
Take this very simple program, counting up to 65534 and reading the button states, as an example:
void setup()
{
TM1638 disp(2, 1, 0);
for (uint16_t j = 0; j != 0xffff; ++j)
{
disp.setDisplayToDecNumber(j, 0);
disp.setLEDs(disp.getButtons());
}
}
void loop() {}
Using the TM16xx library for code.google.com, the compiled binary has the following size (note the 88 bytes of SRAM used as well):
text data bss dec hex filename
2814 88 9 2911 b5f obj/tm1638_org.elf
With the new, attached library, the binary size is:
text data bss dec hex filename
1178 0 0 1178 49a obj/tm1638.elf
Running on a Digispark (ATTiny85), the program takes this long to count from 0-65534 while checking the buttons and setting the LEDs accordingly:
"Old" library:
5min, 40s or 340s.
"New" library:
39s (!!!!)
So the old library allows about 120 refreshes per second while the new one achieves >1600.
And that's on an ATTiny85...
While you rarely want/need 1600 updates per second, speeding up the screen updates and button checks frees up your controller to do other things.
TM1638_v1.00.zip (6.03 KB)