AceSegment
0.7.0
A framework for rendering seven segment LED displays using the TM1637, MAX7219, HT16K33, or 74HC595 controller chips
|
An implementation of LedModule using the TM1637 chip. More...
#include <Tm1637Module.h>
Public Member Functions | |
Tm1637Module (const T_TMII &tmiInterface, const uint8_t *remapArray=nullptr) | |
Constructor. More... | |
void | begin () |
Initialize the module. More... | |
void | end () |
Signal end of usage. More... | |
uint8_t | getNumDigits () const |
Return the number of digits supported by this display instance. | |
void | setPatternAt (uint8_t pos, uint8_t pattern) override |
Set the led digit pattern at position pos. | |
uint8_t | getPatternAt (uint8_t pos) override |
Get the led digit pattern at position pos. | |
void | setBrightness (uint8_t brightness) override |
Set global brightness of all digits. More... | |
void | setDisplayOn (bool on=true) |
Turn off the entire display. More... | |
void | flush () |
Send segment patterns of all digits plus the brightness to the display, if any of the digits or brightness is dirty. More... | |
void | flushIncremental () |
Update only a single digit or the brightness. More... | |
![]() | |
LedModule (uint8_t numDigits) | |
Constructor. More... | |
uint8_t | getNumDigits () const |
Return the number of digits supported by this display instance. More... | |
Friends | |
class | ::Tm1637ModuleTest_flushIncremental |
class | ::Tm1637ModuleTest_flush |
An implementation of LedModule using the TM1637 chip.
The chip communicates using a protocol that is electrically similar to I2C, but does not use an address byte at the beginning of the protocol. We can use a software-based I2C interface.
T_TMII | two wire protocol interface for TM1637, either SoftTmiInterface or SoftTmiFastInterface |
T_DIGITS | number of digits in the LED module (usually 4 or 6) |
Definition at line 91 of file Tm1637Module.h.
|
inlineexplicit |
Constructor.
tmiInterface | instance of either SoftTmiInterface or SoftTmiFastInterface |
remapArray | (optional, nullable) a mapping of the logical digit positions to their physical positions, useful for 6-digt LED modules using the TM1637 chip whose digits are wired out of order |
Definition at line 102 of file Tm1637Module.h.
|
inline |
Initialize the module.
The SoftTmiInterface object must be initialized separately.
remapArray | optional array of positions to handle LED modules whose digit ordering is physically different than the logical ordering (where digit 0 is on the left, and digit (T_DIGITS-1) is on the far right). |
Definition at line 124 of file Tm1637Module.h.
|
inline |
|
inline |
Send segment patterns of all digits plus the brightness to the display, if any of the digits or brightness is dirty.
Takes about 22 ms using a 100 microsecond delay.
Definition at line 187 of file Tm1637Module.h.
|
inline |
Update only a single digit or the brightness.
This method must be called (T_DIGITS + 1) times to update the digits of entire module, including the brightness which is updated using a separate step. Uses the mFlushStage and the mIsDirty bit array to update only the part that needs updating.
This method should be used if the processor cannot be blocked for the entire duration of the flush() method (e.g. on the ESP8266, which will cause a WDT reset when it is blocked for more than 20-40 ms).
Using 100 micro delay, I see the following durations:
1) If brightness is updated on every iteration, I get 'min/avg/max:4/494/13780', so a maximum of 14 ms, which is still a little bit high.
2) If brightness is updated during its own mFlushStage (== T_DIGITS), then I see min/avg/max:4/492/10152
, saving about 3.5ms from the latency. The side effect is a slightly flicker when the display and brightness changes at the same time, because this incrementally updating function makes those changes in 2 steps.
The incremental flushing must use fixed addressing mode to write specific digits, which adds extra commands to the wire protocol to the LED module. If this algorithm is used to send all the digits in one-shot, then this method is about 50% slower (30 ms), compared to flush() (22 ms).
Technical note: The TM1637 datasheet seems to suggest that the brightness must always be sent after a set of digits are sent. However, experimentation shows that the brightness can be sent as an independent transimission, so this method splits out each digit and the brightness as separate iterations.
Definition at line 249 of file Tm1637Module.h.
|
inlineoverridevirtual |
Set global brightness of all digits.
Different subclasses will interpret the brightness integer value differently.
Implements ace_segment::LedModule.
Definition at line 156 of file Tm1637Module.h.
|
inline |
Turn off the entire display.
The brightness is not affected so when it is turned back on, the previous brightness will be used.
Definition at line 169 of file Tm1637Module.h.