-
Notifications
You must be signed in to change notification settings - Fork 38
TM16xxDisplay class reference
Complete examples can be found here:
Interactive Wokwi examples for display.println()
on a TM1637 4-digit display:
Using a pointer to a TM16xx object, the TM16xxDisplay object can be created.
-
TM16xx *pTM16xx
- pointer to a chip specific TM16xx object -
byte nNumDigits
- number of digits used in the display After creating the TM16xxDisplay object, it gives access to additional functions to show text or numbers on a display; such as the familiarprint()
andprintln()
functions.
Usage:
#include <TM1637.h>
TM1637 module(3, 4); // dataPin: 3, clockPin: 4 (no strobePin on TM1637)
TM16xxDisplay display(&module, 4); // pointer to TM1637 object, 4 digits
Combined display constructor: TM16xxDisplay(TM16xx *apTM16xx[], byte nNumModules, byte nNumDigitsTotal)
Combine multiple displays into a single display, e.g. for printing larger text.
- TM16xx *apTM16xx[] - array of TM16xx object pointers
- byte nNumModules - number of TM16xx objects
- byte nNumDigitsTotal - total number of digits
Usage:
#include <TM1638.h>
#include <TM1637.h>
TM1638 module1(8, 9, 7); // dataPin: 8, clockPin: 9, strobePin: 7, using default of 8 digits for TM1638
TM1637 module2(3, 4); // dataPin: 3, clockPin: 4 (no strobePin on TM1637)
TM16xx arr[]={&module1, &module2};
TM16xxDisplay display(arr, 2, 12); // array with object pointers, 2 objects in the array, total of 12 digits
Set the brightness of the display or switch it off.
-
byte intensity
- intensity 0-7, 0=off, 7=bright
Clear the entire display.
Usage:
display.clear();
Sets flipped state of the entire display (every digit is rotated 180 degrees)
-
bool flipped
- flip the display: true, false.
Note: when the display consists of multiple individual displays, all displays are flipped.
setDisplayToString(const char* string, const word dots=0, const byte pos=0, const byte font[] = TM16XX_FONT_DEFAULT)
Set the display to show a C-string or char array.
-
const char* string
- the C-string or char array to be displayed -
const word dots
- bitwise representation of the decimal point state between each digit (up to max 16 digits) -
const byte pos
- position to start displaying text. Default position is 0 -
const byte font[]
- font used to display the text. Defaults to using the built-in 7-segment font
setDisplayToString(String string, const word dots=0, const byte pos=0, const byte font[] = TM16XX_FONT_DEFAULT)
Set the display to show a String object. Defaults to using the built-in 7-segment font.
-
String string
- the String object to be displayed -
const word dots
- bitwise representation of the decimal point state between each digit (up to max 16 digits) -
const byte pos
- position to start displaying text. Default position is 0 -
const byte font[]
- font used to display the text. Defaults to using the built-in 7-segment font
Show the text "error". (Implemented for historic reasons. May become deprecated in later releases).
setDisplayToDecNumber(unsigned long number, byte dots, bool leadingZeros = true, const byte numberFont[] = TM16XX_NUMBER_FONT)
Set the display to a unsigned decimal number (with or without leading zeros).
-
unsigned long number
- the multi-digit number to be displayed. Will be right aligned according the number of digits specified in the constructor -
byte dots
- bitwise representation of the decimal point state between each digit -
bool leadingZeros
- show or hide leading zeros. Default value is true -
const byte numberFont[]
- font used to display the numbers. Defaults to the hexadecimal 7-segment font
Usage:
display.setDisplayToDecNumber(1234, bit(2)); // show number 1234 with dot on position 2: 123.4
setDisplayToSignedDecNumber(signed long number, byte dots, bool leadingZeros = true, const byte numberFont[] = TM16XX_NUMBER_FONT)
Set the display to a signed decimal number (with or without leading zeros). Minus sign will be shown as needed on position 0 with the number right aligned.
-
signed long number
- the multi-digit number to be displayed. Will be right aligned according the number of digits specified in the constructor -
byte dots
- bitwise representation of the decimal point state between each digit -
bool leadingZeros
- show or hide leading zeros. Default value is true -
const byte numberFont[]
- font used to display the numbers. Defaults to the hexadecimal 7-segment font
Usage:
display.setDisplayToSignedDecNumber(-1234, bit(2)); // show number -1234 with dot on position 2: -123.4
setDisplayToHexNumber(unsigned long number, byte dots, bool leadingZeros = true, const byte numberFont[] = TM16XX_NUMBER_FONT)
Set the display to a unsigned hexadecimal number (with or without leading zeros).
Set the display to a unsigned binary number.
Set the position for print() and println() to start printing.
- int8_t nPos - print position. Can be negative to support scrolled printing. First position is 0.
Prints data to display as human-readable ASCII text. Continue subsequent print()/println() at end of printed text.
Prints data to display as human-readable ASCII text. Continue subsequent print()/println() at start of line.
The print()
/println()
functions can take many forms. Numbers are printed using an ASCII character for each digit. Floats are similarly printed as ASCII digits, defaulting to two decimal places. Bytes are printed as a single character. Characters and strings are printed as is. All numbers are printed left-aligned. See the Arduino print reference for more details.
Examples:
-
display.print(78, BIN);
displays "1001110" -
display.print(78, OCT);
displays "116" -
display.print(78, DEC);
displays "78" -
display.print(78, HEX);
displays "4E" -
display.print(1.23456, 0);
displays "1" -
display.print(1.23456, 2);
displays "1.23" -
display.print(1.23456, 4);
displays "1.2346" -
display.print("x="); display.print(123);
displays "x=123"
You can pass flash-memory based strings to display.print() by wrapping them with F(). For example:
-
display.print(F("Hello World"));
displays "Hell" on a four digit display. Multiple displays can be combined to form a larger display.