TM1638 Libray
Default Construtor Reference
Instantiate a TM1638 module specifying the display state, the starting intensity and thedata,clockandstobepins.
TM1638(byte dataPin,byte clockPin,byte strobePin,boolean activateDisplay,byte intensity);
For the inverted module
InvertedTM1638(byte dataPin,byte clockPin,byte strobePin,boolean activateDisplay,byte intensity);
For the TM1640 module
TM1640(byte dataPin,byte clockPin,boolean activateDisplay,byte intensity);
Argument / Detail / DefaultdataPin / The pin to use for Data I/O / required
clockPin / The pin to use for Clock / required
strobePin / The pin to use for Strobe (selector) / required
activateDisplay / True to activate display on constructing, false otherwise. / true
intensity / The starting intensity from 0 (lowest) to 7 (highest) / 7
Example
#include <TM1638.h>
#include <TM16XXFonts.h>
//IO definiálása
int mapRele[8]={A0,A1,A2,A3,A4,A5,A6,A7};
int mapData=8;
int mapClk=9;
int mapStrobe[6]={7,6,5,4,3,2};
TM1638 module(mapData,mapClk,mapStrobe[0],1,7);
void setup és loop csak később!
Define a module on data pin 8, clock pin 9 and strobe pin 7:
TM1638 module1(8,9,7);
Define a module on data pin 8, clock pin 9 and strobe pin 6, with the display inactive at start:
TM1638 module2(8,9,6,false);
Define a module on data pin 8, clock pin 9 and strobe pin 5, with the display active and the starting intensity at 1:
TM1638 module3(8,9,5,true,1);
Define an inverted module on data pin 8, clock pin 9 and strobe pin 4, with the display active and the starting intensity at 1:
InvertedTM1638 module4(8,9,4,true,1);
Define an TM1640 module on data pin 8 and clock pin 9 with the display active and the starting intensity at 1:
TM1640 module5(8,9,true,1);
clearDisplay Reference (TM1638/TM1640)
Clears the display.
void clearDisplay();
Argument / Detail / DefaultExample
Clear the display onmodule1.
module1.clearDisplay();
clearDisplayDigit Reference (TM1638/TM1640)
Clear a single 7-segment display.
void clearDisplayDigit(byte pos,boolean dot);
Argument / Detail / Defaultpos / The display to clear, starting at position 0 (leftmost). / required
dot / The dot state on the 7-segment display / required
Example
Clear the second 7-segment display (counting from the left), but leave the dot lit.
module1.clearDisplayDigit(1,true);
Clear the third 7-segment display (counting from the left), including the dot.
module1.clearDisplayDigit(2,false);
getButtons Reference (TM1638)
Returns the pressed buttons as a bit set (left to right).
byte getButtons();
Argument / Detail / DefaultExample
The expression is true if the leftmost button is pressed:
module1.getButtons()==0b00000001
The expression is true if the rightmost button is pressed:
module1.getButtons()==0b10000000
The expression is true if both middle buttons are pressed:
module1.getButtons()==0b00011000
setDisplay Reference (TM1638/TM1640)
Set the 7-segment displays to the 8 values (left to right)
void setDisplay(constbyte values[]);
Argument / Detail / Defaultvalues / The values for each of the 8 7-segment displays from the the leftmost to the rightmost. / required
Example
Light a single segment on each of the 7-segment displays (and only the dot on the rightmost one):
byte values[]={1,2,4,8,16,32,64,128};
module1.setDisplay(values);
setDisplayDigit Reference (TM1638/TM1640)
Set a single display to a digit.
void setDisplayDigit(byte digit,byte pos,boolean dot,constbyte numberFont[]);
Argument / Detail / Default / Sincedigit / The digit to set / required
pos / The 7-segment display to set. 0 for the leftmost, 7 for the rightmost / required
dot / The dot status for the display / required
numberFont / The font (segment data) to use for numbers, defaulting to the built-in font. / NUMBER_FONT, the built-in number font / v1.5.0
Example
Set the leftmost display to a "6.":
module1.setDisplayDigit(6,0,true);
setDisplayToBinNumber Reference (TM1638)
Set the display to a binary number.
void setDisplayToBinNumber(byte number,byte dots,constbyte numberFont[]);
Argument / Detail / Default / Sincenumber / The number to display / required
dots / The dots to set (bitwise) / required
numberFont / The font (segment data) to use for numbers, defaulting to the built-in font. / NUMBER_FONT, the built-in number font / v1.5.0
Example
Display "1.0.1.0.1.0.1.0.":
module1.setDisplayToBinNumber(0b10101010,0xFF);
Display 15 in binary with no dots:
module1.setDisplayToBinNumber(15,0);
setDisplayToDecNumber Reference (TM1638)
Set the display to a unsigned decimal number, with or without leading zeros.
void setDisplayToDecNumber(unsignedlong number,byte dots,boolean leadingZeros,constbyte numberFont[]);
Argument / Detail / Default / Sincenumber / The number to display / required
dots / The dots to set (bitwise) / required
leadingZeros / trueto display leading zeros, false otherwise / true
numberFont / The font (segment data) to use for numbers, defaulting to the built-in font. / NUMBER_FONT, the built-in number font / v1.5.0
Example
Display "00000033.":
module1.setDisplayToDecNumber(33,1);
Display 15 in decimal with no dots and no leading zeroes:
module1.setDisplayToDecNumber(15,0,false);
setDisplayToSignedDecNumber Reference (TM1638)
Set the display to a signed decimal number, with or without leading zeros.
void setDisplayToSignedDecNumber(unsignedlong number,byte dots,boolean leadingZeros,constbyte numberFont[]);
Argument / Detail / Default / Sincenumber / The number to display / required
dots / The dots to set (bitwise) / required
leadingZeros / trueto display leading zeros, false otherwise / true
numberFont / The font (segment data) to use for numbers, defaulting to the built-in font. / NUMBER_FONT, the built-in number font / v1.5.0
Example
Display "-0000033.":
module1.setDisplayToDecNumber(-33,1);
Display -15 in decimal with no dots and no leading zeroes:
module1.setDisplayToDecNumber(-15,0,false);
setDisplayToError Reference (TM1638/TM1640)
Set the display to an error message. Is called on overflow insetDisplayToDecNumber
void setDisplayToError();
Argument / Detail / Default / SinceExample
Display an error:
module1.setDisplayToError();
setDisplayToHexNumber Reference (TM1638)
Set the display to a unsigned hexadecimal number, with or without leading zeros.
void setDisplayToHexNumber(unsignedlong number,byte dots,boolean leadingZeros,constbyte numberFont[]);
Argument / Detail / Default / Sincenumber / The number to display / required
dots / The dots to set (bitwise) / required
leadingZeros / trueto display leading zeros, false otherwise / true
numberFont / The font (segment data) to use for numbers, defaulting to the built-in font. / NUMBER_FONT, the built-in number font / v1.5.0
Example
Display "00000A1A.":
module1.setDisplayToHexNumber(0x0a1a,1);
Display 15 in hexadecimal with no dots and no leading zeroes:
module1.setDisplayToHexNumber(15,0,false);
setDisplayToString Reference (TM1638/TM1640)
Set the display to the string.
void setDisplayToString(constchar*string,const word dots,constbyte pos,constbyte font[]);
Argument / Detail / Default / Sincestring / The text to display / required
dots / The dots to set (bitwise) / 0 / v1.4.0
pos / The position to start. 0 for the leftmost, 7 for the rightmost / required / v1.6.0
font / The font (segment data) to use, defaulting to the built-in font. / FONT_DEFAULT, the built-in font
Example
Display "Ricardo." using the built-in font:
char* name ="Ricardo.";
module.setDisplayToString(name);
Display "Ricardo " with dots on every other letter:
char* name ="Ricardo ";
module.setDisplayToString(name,0b10101010);
Display "foo bar":
char* foo ="foo";
char* bar ="bar";
module.setDisplayToString(foo,0);
module.setDisplayToString(bar,0,4);
Font character data
Fonts can be created like the built-in font:
// definition for the displayable ASCII chars
constbyte FONT_DEFAULT[]={
0b00000000,// (32) <space>
0b10000110,// (33) !
0b00100010,// (34) "
0b01111110,// (35) #
0b01101101,// (36) $
0b00000000,// (37) %
0b00000000,// (38)
0b00000010,// (39) '
0b00110000,// (40) (
0b00000110,// (41) )
0b00000000,// (42) *
0b00000000,// (43) +
0b00000100,// (44) ,
0b01000000,// (45) -
0b10000000,// (46) .
0b01010010,// (47) /
0b00111111,// (48) 0
0b00000110,// (49) 1
0b01011011,// (50) 2
0b01001111,// (51) 3
0b01100110,// (52) 4
0b01101101,// (53) 5
0b01111101,// (54) 6
0b00100111,// (55) 7
0b01111111,// (56) 8
0b01101111,// (57) 9
0b00000000,// (58) :
0b00000000,// (59) ;
0b00000000,// (60)
0b01001000,// (61) =
0b00000000,// (62)
0b01010011,// (63) ?
0b01011111,// (64) @
0b01110111,// (65) A
0b01111111,// (66) B
0b00111001,// (67) C
0b00111111,// (68) D
0b01111001,// (69) E
0b01110001,// (70) F
0b00111101,// (71) G
0b01110110,// (72) H
0b00000110,// (73) I
0b00011111,// (74) J
0b01101001,// (75) K
0b00111000,// (76) L
0b00010101,// (77) M
0b00110111,// (78) N
0b00111111,// (79) O
0b01110011,// (80) P
0b01100111,// (81) Q
0b00110001,// (82) R
0b01101101,// (83) S
0b01111000,// (84) T
0b00111110,// (85) U
0b00101010,// (86) V
0b00011101,// (87) W
0b01110110,// (88) X
0b01101110,// (89) Y
0b01011011,// (90) Z
0b00111001,// (91) [
0b01100100,// (92) \ (this can't be the last char on a line, even in comment or it'll concat)
0b00001111,// (93) ]
0b00000000,// (94) ^
0b00001000,// (95) _
0b00100000,// (96) `
0b01011111,// (97) a
0b01111100,// (98) b
0b01011000,// (99) c
0b01011110,// (100) d
0b01111011,// (101) e
0b00110001,// (102) f
0b01101111,// (103) g
0b01110100,// (104) h
0b00000100,// (105) i
0b00001110,// (106) j
0b01110101,// (107) k
0b00110000,// (108) l
0b01010101,// (109) m
0b01010100,// (110) n
0b01011100,// (111) o
0b01110011,// (112) p
0b01100111,// (113) q
0b01010000,// (114) r
0b01101101,// (115) s
0b01111000,// (116) t
0b00011100,// (117) u
0b00101010,// (118) v
0b00011101,// (119) w
0b01110110,// (120) x
0b01101110,// (121) y
0b01000111,// (122) z
0b01000110,// (123) {
0b00000110,// (124) |
0b01110000,// (125) }
0b00000001,// (126) ~
};
setDisplayToString Reference (TM1638/TM1640)
Set the display to the string.
void setDisplayToString(Stringstring,const word dots,constbyte pos,constbyte font[]);
Argument / Detail / Default / Sincestring / The text to display / required
dots / The dots to set (bitwise) / 0 / v1.4.0
pos / The position to start. 0 for the leftmost / required / v1.6.0
font / The font (segment data) to use, defaulting to the built-in font. / FONT_DEFAULT, the built-in font
Example
Display "Ricardo." using the built-in font:
String name ="Ricardo.";
module.setDisplayToString(name);
Display "Ricardo " with dots on every other word:
String name ="Ricardo ";
module.setDisplayToString(name,0b10101010);
Display "foo bar":
String foo ="foo";
String bar ="bar";
module.setDisplayToString(foo,0);
module.setDisplayToString(bar,0,4);
Font character data
Fonts can be created like the built-in font:
see above
setLED Reference (TM1638)
Controls a LED.
void setLED(byte color,byte pos);
Argument / Detail / Defaultcolor / The color of the LED. Can be set toTM1638_COLOR_RED(for red),TM1638_COLOR_GREEN(for green) or both. Can be set to TM1638_COLOR_NONE to clear the LED. / required
pos / The LED to set. 0 for the leftmost, 7 for the rightmost / required
Example
Sets the leftmost LED to green:
module1.setLED(TM1638_COLOR_GREEN,0);
Sets the leftmost LED to greenandred:
module1.setLED(TM1638_COLOR_GREEN + TM1638_COLOR_RED,0);
Clears the leftmost LED:
module1.setLED(TM1638_COLOR_NONE,0);
setLEDs Reference (TM1638)
Set all the LEDs.
void setLEDs(word led);
Argument / Detail / Defaultled / The LEDs to set. MSB byte for the green LEDs, LSB for the red LEDs. / required
Example
Light up all the red LEDs.
module1.setLEDs(0x00FF);
Light up all the green LEDs.
module1.setLEDs(0xFF00);
Light up all the LEDs.
module1.setLEDs(0xFFFF);
setupDisplay Reference (TM1638/TM1640)
Set the display (all 7-segments) and LEDs on or off and the specifies the intensity.
void setupDisplay(boolean active,byte intensity);
Argument / Detail / Defaultactive / truefor on,falsefor off / required
intensity / The starting intensity from 0 (lowest) to 7 (highest) / required
Example
Activate display at maximum intensity:
module1.setupDisplay(true,7);
Inactivate the display and set the intensity to the lowest:
module1.setupDisplay(false,0);