AceSegment
0.12.0
A library for rendering seven segment LED displays using the TM1637, TM1638, 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... | |
void | setDisplayOn (bool on=true) |
Turn off the entire display. More... | |
bool | isFlushRequired () const |
Return true if flushing required. | |
void | flush () |
Send segment patterns of all digits plus the brightness to the display. More... | |
void | flushIncremental () |
Update only a single digit or the brightness. More... | |
uint8_t | readButtons () const |
Read the 1 byte with key scan with the bits coming out in LSBFIRST order with the following bits: S0 S1 S2 K1 K2 X X X . More... | |
![]() | |
LedModule (uint8_t *patterns, uint8_t numDigits) | |
Constructor. More... | |
uint8_t | getNumDigits () const |
Return the number of digits supported by this display instance. | |
void | setPatternAt (uint8_t pos, uint8_t pattern) |
Set the led digit pattern at position pos. | |
uint8_t | getPatternAt (uint8_t pos) const |
Get the led digit pattern at position pos. | |
void | setBrightness (uint8_t brightness) |
Set global brightness of all digits. More... | |
uint8_t | getBrightness () const |
Get the current brightness. | |
Friends | |
class | ::Tm1637ModuleTest_flushIncremental |
class | ::Tm1637ModuleTest_flush |
Additional Inherited Members | |
![]() | |
void | begin () |
Subclasses should call this from its own begin(). | |
void | end () |
Subclasses should call this from its own end(). More... | |
void | setDigitDirty (uint8_t pos) |
Set the dirty bit of digit pos . | |
void | clearDigitDirty (uint8_t pos) |
Clear the dirty bit of digit pos . | |
bool | isDigitDirty (uint8_t pos) const |
Check the dirty bit of digit pos . | |
void | clearDigitsDirty () |
Clear dirty bits of all digits. | |
bool | isAnyDigitDirty () const |
Return true if any digits are dirty. | |
bool | isBrightnessDirty () const |
Check if the brightness level is dirty. | |
void | setBrightnessDirty () |
Mark the brightness as dirty. | |
void | clearBrightnessDirty () |
Clear the dirty bit for brightness. | |
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.
T_TMII | class that implements the two wire protocol interface for TM1637, usually one of the classes from the AceTMI library: SimpleTmi1637Interface or SimpleTmi1637FastInterface. |
T_DIGITS | number of digits in the LED module (usually 4 or 6) |
Definition at line 75 of file Tm1637Module.h.
|
inlineexplicit |
Constructor.
tmiInterface | instance of TM1637 interface class |
remapArray | (optional, nullable) a mapping of the logical digit positions to their physical positions, useful for 6-digt LED modules whose digits are wired out of order |
Definition at line 85 of file Tm1637Module.h.
|
inline |
Initialize the module.
The SimpleTmi1637Interface or SimpleTmi1637FastInterface object must be initialized separately.
Definition at line 102 of file Tm1637Module.h.
|
inline |
|
inline |
Send segment patterns of all digits plus the brightness to the display.
Takes about 22 ms using a 100 microsecond delay.
The isFlushRequired() method can be used to optimize the number of calls to flush(), but often it is not necessary.
Definition at line 144 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 211 of file Tm1637Module.h.
|
inline |
Read the 1 byte with key scan with the bits coming out in LSBFIRST order with the following bits: S0 S1 S2 K1 K2 X X X
.
The S0,S1,S2 bits are the binary encoding of one of the SG1 to SG8 segment lines using a 0-index, so SG1 is 0 and SG8 is 7. The K1 and K2 bits are not encoded and correspond directly to the K1 and K2 control lines.
The Sn and Kn lines seem to be pulled up high, so when no buttons are pressed, the data value from the TM1637 controller is 0xFF. When a button is pressed, the corresponding Kn and Sn lines go to 0. For example, if the button on SG2 and K1 is pressed, the SG2 generates a bit pattern of 0b??101
and the K1 line corresponds to bit pattern 0b10???
, so when these are combined, the final button data is 0b11110101
or 0xF5.
Definition at line 265 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 123 of file Tm1637Module.h.