Skip to content

TM16xxDisplay class reference

Maxint R&D edited this page Feb 28, 2025 · 4 revisions
Use Function
Single display constructor TM16xxDisplay(TM16xx *pTM16xx, byte nNumDigits)
Combined display constructor TM16xxDisplay(TM16xx *apTM16xx[], byte nNumModules, byte nNumDigitsTotal)
Change brightness setIntensity(byte intensity)
Clear display clear()
Flip display setDisplayFlipped(bool flipped)
Display char* setDisplayToString(const char* string, const word dots=0, const byte pos=0, const byte font[] = TM16XX_FONT_DEFAULT)
Display String setDisplayToString(String string, const word dots=0, const byte pos=0, const byte font[] = TM16XX_FONT_DEFAULT)
Display error setDisplayToError()
Display hex number setDisplayToHexNumber(unsigned long number, byte dots, bool leadingZeros = true, const byte numberFont[] = TM16XX_NUMBER_FONT)
Display decimal number setDisplayToDecNumber(unsigned long number, byte dots, bool leadingZeros = true, const byte numberFont[] = TM16XX_NUMBER_FONT)
Display signed number setDisplayToSignedDecNumber(signed long number, byte dots, bool leadingZeros = true, const byte numberFont[] = TM16XX_NUMBER_FONT)
Display binary number setDisplayToBinNumber(byte number, byte dots, const byte numberFont[] = TM16XX_NUMBER_FONT)
Set print cursor setCursor(int8_t nPos)
Print data print() println()

Complete examples can be found here.

Interactive Wokwi example: display.println()


TM16xxDisplay class functions

Constructor: TM16xxDisplay(TM16xx *pTM16xx, byte nNumDigits)

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 familiar print() and println() 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

setIntensity(byte intensity)

Set the brightness of the display or switch it off.

  • byte intensity - intensity 0-7, 0=off, 7=bright

clear()

Clear the entire display

setDisplayFlipped(bool flipped)

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)

setDisplayToString(String string, const word dots=0, const byte pos=0, const byte font[] = TM16XX_FONT_DEFAULT)

Set the display to the String (defaults to built in font)

setDisplayToError()

Show the text "error". (Implemented for historic reasons. May become deprecated in later releases).

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)

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)

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)

setDisplayToBinNumber(byte number, byte dots, const byte numberFont[] = TM16XX_NUMBER_FONT)

Set the display to a unsigned binary number

setCursor(int8_t nPos)

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.

print()

Prints data to display as human-readable ASCII text. Continue next print()/println() at end of print().

println()

Prints data to display as human-readable ASCII text. Continue next print()/println() at start of line.

These 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 sent as a single character. Characters and strings are sent as is. 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"

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 a form larger display.
Clone this wiki locally