Seven Segment Display Library

Written by Dean Reading, 2013

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/file/d/0Bwrp4uluZCpNdE9oWTY0M3BncTA/edit?usp=sharing

Version 2.3: Adds brightness control.

Version 2.2: Allows for 1, 2 or 3 digit displays to be used.

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 deanreading@hotmail.com

Thanks to Mark Chambers and Nathan Seidle for code used in updates.

 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);

 Brightness
 To change the brightness of the display, use the brightness function.
 The brightness is defined by a value from 0 to 100. e.g. call sevseg.Brightness(90);
 Obtain the current brightness value with the same function.
 e.g. Serial.println(sevseg.Brightness());
 If you wish for the display to be any dimmer, run PrintOutput less frequently.

 1, 2 or 3 digit displays:
 NUM_DIGITS in SevSeg.h allows you to use a 1, 2 or 3 digit display.  The number processing
 is not altered, so it is really just a quick fix.  This means that 'out of bounds' is
 still considered above 9999 or below -999, regardless of NUM_DIGITS.
 You must still feed in all 12 pins.  However, the program will not alter the digit pins
 that are higher than NUM_DIGITS.
 eg if NUM_DIGITS is 2, then D3 and D4 won't be altered.

Share