AceSegment
A library for rendering seven segment LED modules using the TM1637, TM1638, MAX7219, HT16K33, or 74HC595 controller chip.
Install / Use
/learn @bxparks/AceSegmentREADME
AceSegment
An adjustable, configurable, and extensible framework for rendering seven segment LED displays on Arduino platforms. The library supports many types of LED displays:
- modules using the TM1637 controller chip over its custom 2-wire protocol
- modules using the TM1638 controller chip over its custom 3-wire protocol
- modules using the MAX7219/MAX7221 controller chip over SPI
- modules using the HT16K33 controller chip over I2C
- modules using two 74HC595 shift register chips over SPI
- modules using a hybrid of one 74HC595 chip and direct GPIO connections
- modules directly connected to the GPIO pins, no controller chips
The first 5 types are readily available from retail outlets such as Amazon and eBay, in multiple colors and sizes. They look like these:
TM1637

TM1638

MAX7219

HT16K33

74HC595

The final 2 types of modules (hybrid and directly connected) are usually custom creations. Here is an example of an LED module that I built myself a few years ago using a single 74HC595 chips and 4 transistors:
Hybrid

Here is another one which uses only 4 transistors without any controller chip. The 8 segment lines and the 4 digit lines are controlled directly by 12 GPIO pins of the microcontroller:
Direct

The AceSegment library hopes to support as many seven-segment displays as practical within a single framework. Different types of seven-segment LED modules using different controller chips are similar enough to each other that code at the application layer can be mostly agnostic to the hardware differences. The library is organized into hardware-dependent components and hardware-independent components to allow application code to be written without worrying too much about the low-level details of the specific LED module.
This library is designed to ensure that client applications pay only for what
they use. Most of the code is written as C++ templates to avoid creating static
resources that cannot be optimized away. No virtual methods are used in this
library, making the code size smaller and execution speed a little faster. There
is no direct dependency to the <Wire.h>, <SPI.h>, <AceWire.h>,
<AceSPI.h>, or <AceTMI.h> libraries from this library. (On AVR processors,
simply adding #include <Wire.h> increases flash usage by about 1100 bytes even
if nothing is used from the <Wire.h> library.)
Version: 0.13.0 (2023-03-15)
Status: First public release at 0.9.1.
Changelog: CHANGELOG.md
Table of Contents
- Installation
- Documentation
- High Level Overview
- Usage
- Advanced Usage
- Resource Consumption
- System Requirements
- Bugs And Limitations
- Alternative Libraries
- License
- Feedback and Support
- Authors
<a name="Installation"></a>
Installation
The latest stable release is available in the Arduino IDE Library Manager. Search for "AceSegment". Click install.
The development version can be installed by cloning the
GitHub repository, checking out the
default develop branch, then manually copying over to or symlinking from the
./libraries directory used by the Arduino IDE. (The result is a directory
or a link named ./libraries/AceSegment.)
The master branch contains the stable releases.
<a name="SourceCode"></a>
Source Code
The source files are organized as follows:
src/AceSegment.h- main header filesrc/ace_segment/- implementation filessrc/ace_segment/testing/- internal testing filestests/- unit tests which require AUnitexamples/- example sketchesdocs/- contains the doxygen docs and additional manual docs
<a name="Dependencies"></a>
Dependencies
This library library has a direct dependency on:
- AceCommon (https://github.com/bxparks/AceCommon)
The following libraries are listed in the depends clause of
library.properties so that they are automatically installed by the Arduino
Library Manager for convenience. However these libraries are pulled into the
executable only when the client application explicitly uses them.
- AceSPI (https://github.com/bxparks/AceSPI)
- Needed by
Hc595Module,Max7219Module, andHybridModule
- Needed by
- AceTMI (https://github.com/bxparks/AceTMI)
- Needed by
Tm1637ModuleandTm1638Module
- Needed by
- AceWire (https://github.com/bxparks/AceWire)
- Needed by
Ht16k33Module
- Needed by
The following library is a companion library to AceSegment that provides more
powerful and convenient "Writer" classes. It is not listed in the depends
clause, so must be installed manually:
- AceSegmentWriter (https://github.com/bxparks/AceSegmentWriter)
- Provides more powerful and convenient classes to write quantities (numbers, characters, strings, etc) to the LED module.
The unit tests depend on:
- AUnit (https://github.com/bxparks/AUnit)
Some of the examples may depend on:
- TimerOne (https://github.com/PaulStoffregen/TimerOne)
- one of the DigitalWriteFast libraries, for example:
- https://github.com/watterott/Arduino-Libs/tree/master/digitalWriteFast
- https://github.com/NicksonYap/digitalWriteFast
<a name="Documentation"></a>
Documentation
- this
README.mdfile - DEVELOPER.md
- Internal technical notes to developers of the library.
- scanning_module.md
- Information about
ScanningModuleandLedMatrixclasses. These are the implementation classes forHc595Module,HybridModuleandDirectModule.
- Information about
- capacitor_removal.md
- Removing the 10 nF capacitors on certain TM1637 LED modules
- Doxygen docs
- On Github pages.
<a name="Examples"></a>
Examples
The following example sketches are provided:
- Basic
- Intermediate
- Advanced
- DirectDemo.ino
- Demo of an LED module with no controller, all digit and segment pins wired directly to the microcontroller
- Uses
DirectModuleclass
- DirectFast4Demo.ino
- same as
DirectDemobut usingDirectFast4Modulewhich usesdigitalWriteFast()
- same as
- HybridDemo.ino
- Demo of an LED module that uses a single 74HC595 shift register on the segment pins, but the digit pins are wired directly to the microcontroller
- DirectDemo.ino
