I've been trying to avoid multiplexing for a ganged LED display and came across this LED package. You can find them listed on eBay under 5V MAX7219 8-Digit Red LED and they sell for less than $5. The library can be downloaded at:
http://www.pjrc.com/teensy/td_libs_LedControl.html
The sample code below shows how easy it is to interface with the display. I have no financial interest in the device, but found it perfect for my ATtiny85 project that requires more than 4 digits.
/*****
Make sure your LedControl library is added to the Arduino IDE and that
the first exxecutable lines in the header file contain:
#ifndef LedControl_h
#define LedControl_h
#if (ARDUINO < 100)
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
You will get error messages on Arduino IDE 1.05 if this change is not made. THe
LedControl library may be downloaded at:
http://www.pjrc.com/teensy/td_libs_LedControl.html
Documentation is also at the site.
Code provided by Dr. Jack Purdum March 12, 2014
*****/
#include <LedControl.h>
#include <stdlib.h>
#define ARDUINOUNO
//#define ARDINOMEGA 1
#ifdef ARDUINOUNO // Uncomment ARDUINOUNO and comment out ARDUINOMEGA
#define DINPIN 10 // to use these pins...
#define CLKPIN 13
#define LOADPIN 11
#else // ...otherwise MEGA pins are assumed
#define DINPIN 45
#define CLKPIN 44
#define LOADPIN 43
#endif
#define DISPLAYDIGITS 8
// inputs: DIN pin (45), CLK pin (44), LOAD pin (43). number of chips (1)
// The number of chips is one even though it controls 8 LED digit displays.
LedControl mydisplay = LedControl(DINPIN, CLKPIN, LOADPIN, 1);
void setup() {
mydisplay.shutdown(0, false); // turns on display
mydisplay.setIntensity(0, 5); // 15 = brightest
}
void loop() {
int i, j;
char buffer[10];
mydisplay.clearDisplay(0); // Clear out previous data
for (i = 0; i < DISPLAYDIGITS; i++) {
for (j = 1; j < 10; j++) {
mydisplay.setDigit(0, i, j, false); // Count to 10
delay(100);
}
mydisplay.setDigit(0, i, 0, false); // Repeat for each digit
delay(100);
}
mydisplay.clearDisplay(0);
ConvertNumberToString(1234, 1, buffer); // Format with one decimal point
delay(2000);
mydisplay.clearDisplay(0);
ConvertNumberToString(5678, 0, buffer); // Format with no decimal point
delay(2000);
}
/*****
This function converts a number to a string representation and then displays
it on the LED array. THe output is right-justified on the display.
Parameter List:
float val the number to be converted
unsigned char precision the number of digits after the decimal point
char *buffer a character array. It is assumed to be large
enough to hold the number represented as an
ASCII number plus the null.
Return value:
void
*****/
void ConvertNumberToString(float val, unsigned char precision, char *buffer)
{
int i;
int start;
dtostrf(val, DISPLAYDIGITS, precision, buffer);
start = DISPLAYDIGITS - precision - 1;
for (i = 0; i < DISPLAYDIGITS; i++) {
if (buffer[i] != ' ') { // If we have a digit character
if (buffer[i + 1] == '.') { // Need a decimal point?
mydisplay.setDigit(0, start--, buffer[i] - '0', true); // Yes
i++;
} else {
mydisplay.setDigit(0, start--, buffer[i] - '0', false); // No
}
} else {
start--;
}
}
}