Written by Dean Reading, 2012
Version 2.1: Includes a bug fix that could cause some stray segments lighting up unintentionally.
Version 2.0: Now works for any digital pin arrangement, common anode and common cathode displays.
Direct any questions or suggestions to email@example.com
This library allows an arduino to easily display numbers in decimal format on a 4 digit 7-segment display without a separate 7-segment display controller.
Download it here: https://docs.google.com/open?id=0Bwrp4uluZCpNN1Q4dmFZX1MzWVE
Hardware: 4 digit 7 segment displays use 12 digital pins.
There are: 4 common pins; 1 for each digit. These will be cathodes (negative pins) for common cathode displays, or anodes (positive pins) for common anode displays. I refer to these as digit pins. 8 pins for the individual segments (seven segments plus the decimal point). I refer to these as segment pins.
Connect the four digit pins with four limiting resistors in series to any digital or analog pins. Connect the eight cathodes to any digital or analog pins.
I have a cheap one from China, and the pins of the display are in the following order: Top Row 1,a,f,2,3,b Bottom Row e,d,dp,c,g,4 Where the digit pins are 1-4 and the segment pins are a-g + dp
Software: Call SevSeg.Begin in setup. The first argument (boolean) tells whether the display is common cathode (0) or common anode (1). The next four arguments (bytes) tell the library which arduino pins are connected to the digit pins of the seven segment display. Put them in order from left to right. The next eight arguments (bytes) tell the library which arduino pins are connected to the segment pins of the seven segment display. Put them in order a to g then the dp.
In summary, Begin(type, digit pins 1-4, segment pins a-g,dp)
The calling program must run the PrintOutput() function repeatedly to get the number displayed. To set the number displayed, use the NewNum function. Any number between -999 and 9999 can be displayed. Out of range numbers show up as --. To move the decimal place one digit to the left, use '1' as the second argument in NewNum. For example, if you wanted to display '3.141' you would call NewNum(3141,3);