Arduino library that significantly simplify connection process and usage of a seven-segment display (single-digit type)
In Arduino IDE Sketch -> Include Library -> Manage Libraries.... Then find "Easy SevenSeg"
On GitHub repository Code -> Download Zip
In Arduino IDE Sketch -> Include Library -> Add .ZIP Library.... Then select downloaded archive
#include "EasySevenSeg.h" // Include
EasySevenSeg myDisplay; // Initialize
myDisplay.begin(); // Begin (setups Arduino pins)
myDisplay.printDigit(1); // Print 0 to 9
myDisplay.printLetter("A"); // Print A to F (accepts upper- and lowercase)
There are two types of seven-segment displays.
Look at the picture below. The display has 10 pins in total. Pins #3 and #8 are common. The other eight pins are responsible for a single segment each (yeah, it calls "seven-segment" mostly because of the historical reason).
Get back to the common pins. Depending on what they are we can distinguish two display types:
- Common anode display (common pins are +).
- It means, in order to highlight the segments, the common pins must be "+" (e.g., 5V or HIGH) and the segment pins must be "-" (e.g., GND or LOW)
- Common cathode display (common pins are -).
- It means, in order to highlight the segments, the common pins must be "-" (e.g., GND or LOW) and segment pins must be "+" (e.g., 5V or HIGH)
Note 1: The library is designed for the "common cathode" type. If anyone wants to implement a "common anode", you are welcome to make a pull request.
Note 2: Segments are simple LEDs under the hood. In order to keep them safe, don't forget to use resistors when connecting each of them to "+". 220Ω will be enough.
The begin()
method setups appropriate Arduino pins as OUTPUT.
By default (if no arguments passed to the method) you may use the following pins:
- display pin 1 == 1A on Arduino
- display pin 2 == 2A on Arduino
- display pin 4 == 4A on Arduino
- display pin 5 == 5A on Arduino
- display pin 6 == 6 on Arduino
- display pin 7 == 7 on Arduino
- display pin 9 == 9 on Arduino
- display pin 10 == 10 on Arduino
On the other hand, you may set up your own pin values. Just pass them to the begin(int 1pin, ... int 10pin)
method.
Keep in mind, pins #3 and #8 are omitted, since they are common (see "display types" above).