-
Notifications
You must be signed in to change notification settings - Fork 39
TM16xx base class reference
| Use | Function |
|---|---|
| Constructor | TM16..(byte dataPin, byte clockPin, byte strobePin, byte nDigitsUsed) |
| Initialisation | begin(bool activateDisplay=true, byte intensity=7) |
| Change brightness | setupDisplay(bool active, byte intensity) |
| Flip display | setDisplayFlipped(bool flipped) |
| Clear display | clearDisplay() |
| Set 8 segments | setSegments(byte segments, byte position) |
| Set 16 segments | setSegments16(uint16_t segments, byte position) |
| Set single digit | setDisplayDigit(byte digit, byte pos=0, bool dot=false, const byte numberFont[] = TM16XX_NUMBER_FONT) |
| Show a number | setDisplayToDecNumber(int nNumber, byte bDots=0) |
| Clear single digit | clearDisplayDigit(byte pos, bool dot=false) |
| Set multiple digits | setDisplay(const byte values[], byte size=8) |
| Show a string | setDisplayToString(const char* string, const word dots=0, const byte pos=0, const byte font[] = TM16XX_FONT_DEFAULT) |
| Get button state | uint32_t getButtons() |
Complete examples can be found here.
All chip-specific classes are derived from the TM16xx base class. Depending on the interface they have one or more parameters to specify the connecting pins. For a full overview of all TM16xx chips and interfaces go to TM16xx chips features
Usage:
#include <TM1638.h>
#include <TM1637.h>
TM1638 module1(8, 9, 7, 8); // dataPin: 8, clockPin: 9, strobePin: 7, 8 digits
TM1637 module2(3, 4, 7, 4); // dataPin: 3, clockPin: 4, no strobePin, 4 digitsTo initialize a module/chip begin() can be called in setup(). It typically calls calls setupDisplay() and clearDisplay() to as part of the initialization.
Usage:
setup() {
module.begin();
}Note: Calling begin() isn't mandatory. If it isn't called explicitly in setup(), it will be called implicitly at the first displaying of data.
Set the display (segments and LEDs) on or off and set the intensity/brightness (range 0-7). Use this function for instance to change the brightness after measuring the surrounding light with a light dependent resistor (LDR).
Usage:
module.setupDisplay(true, 3); // on/off, intensity (range 0-7).Note: when the display is switched off using setupDisplay(), the chip/module will not be able to read buttons being pressed.
Sets flipped state of the display. When displaying numbers (or text) every digit will be rotated 180 degrees.
Note that this only affects subsequent displaying of data, not what is currently being shown. If affects all functions that display text or numbers but not setSegments() and setSegments16().
Usage:
module.setDisplayFlipped(true); // flip all subsequent displaying of numbers/text 188 degrees.Clear the display. All LEDs of the display will be switched of and no data is displayed. Usage:
module.clearDisplay(); // clear all digits of the display.Set up to 8 segments of display digit, one digit at a time.
- byte segments - Value representing the state of each segment. Order is bit 0 - 7 for segments A-G,DP.
- byte position - The position of the digit on the display. Order is left to right. 0 is the leftmost digit.
Usage:
module.setSegments(123, 0); // set the segments of digit 0 to 123, this is binary value 0111 1011 for segments ABDEFG, forming the letter 'e'Set up to 16 segments of a display digit, one digit at a time. Some chips/modules can address more than 8 segments per position. Alpha-numeric displays can use this for more accurate character representation.
- byte segments - Value representing the state of each segment. Order is bit 0 - 15 for segments A-G1,DP,G2-N.
- byte position - The position of the digit on the display. Order is left to right. 0 is the leftmost digit.
Usage:
module.setSegments16(0xFF, 0); // set the all segments of digit 0 onFor additional display features use the TM16xxDisplay class
setDisplayDigit(byte digit, byte pos=0, bool dot=false, const byte numberFont[] = TM16XX_NUMBER_FONT)
Set a single display at pos (starting at 0) to a digit (left to right).
- byte digit - the single digit number to be displayed
- byte pos - the position of the display
- bool dot - set decimal point/dot (DP) on or off
- numberFont[] - numeric font used to display the numbers
Set the display to a decimal number.
- int nNumber - the multi digit number to be displayed. Will be right aligned with preceding zeros
- byte bDots - bitwise representation of the decimal point state between each digit
Clear a single display at pos (starting at 0, left to right)
Set the segments of the display to specific values (left to right)
setDisplayToString(const char* 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)
Key-scanning - return the state of up to 32 keys. Note: not all TM16xx chips support key-scanning and sizes are different per chip. For a full overview of all TM16xx chips and the number of buttons that can be scanned, go to TM16xx chips features. Up to 32 key states are supported, but specific chips may support less keys or less combinations. The chip specific derived class method will return a 32-bit value representing the state of each key. Returns 0 if no key is pressed