8x7-segments Display TM1638

Assembly

The connection of the display is set the following way :
tm1638-schema.png
You can find the connection information on the back of the card.

Afficheur ST Nucleo
5V 5V
DIO D4
CLK D3
STB0 D2
GND GND

Usage

At first, it is necessary to include libraries :
It can be downloaded from arduino IDE under Sketch > Include Library > Manage libraries and searching tm1638. Choose TM1638plus.

// Libraries include
#include <TM1638plus.h>

Next we initialise communication pins with the card and we start the communication:

// Card declaration
//           STB  CLK  DIO
TM1638plus tm(D2, D3 , D4);

// Communication and display begin
Serial.begin(115200);
tm.displayBegin();

Now the card is ready to be used and here are the instructions to use the different parts :

  • LEDs :
    The shown card (JY-LKM1638) is equipped with bicolor leds green and red, which is not the case for all TM1638 cards.
    tm.setLEDs(value); : turn on/off leds depending on the value : 0xRRGG where RR et GG are hexadecimal codes to turn on/off the red/green component.
    tm.setLED(position, value); : turn on/off led at indicated position.
// Gestion des leds
tm.setLEDs(0xE006); // turn on leds 6-8 in red and 2-3 in green
tm.setLEDs(0x0180); // turn on led 1 in red and 8 in green
tm.setLED(0, 0);	// turn off led 1
tm.setLED(1,1); 	// turn on led 2 in red
tm.setLED(2,2); 	// turn on led 3 in green
tm.setLED(3,3); 	// turn on led 4 in red and green (light orange)
  • Buttons :
    tm.readButtons(); return a 8-bits word with 1 to indicate the button is pressed. e.g. if tm.keys() return 0b00100001, that means that the 1st and 6th buttons are pressed.
// Get information on the buttons
boutons = tm.readButtons();
  • Segments :
    tm.displayText("word"); : allow to write caracters 0-9, A-Z, space, -, _ and dots. Display is left aligned and doesn’t erase what was previously written if the word is shorter than 8 caracters.
    tm.displayIntNum(nombre, bool); : allow to write an integer. Display is right aligned and erases non-filled cases if bool = false and right aligned filled with 0 if bool = true.
    tm.display7Seg(pos, 0bpgfedcba); : allow to modify a caratcter with the wished configuration according to the following picture :

7_segment_display.jpg

// Segments
tm.displayText("  _--_  ");
tm.displayText("a.b.c.d.e.f.g.h.");

tm.displayIntNum(72, false); 	// "72      "
tm.displayIntNum(-92345, true);	// "-0092345"
  
tm.display7Seg(2, 0b11011011);	// display '2.' on the 3rd caracter
tm.display7Seg(7, 0b01110110);	// display 'H' on the last caracter
  • Brightness adjustment :
    It is possible to change the leds and segments brightness with tm.brightness(value).
// Modify leds and segments brightness
tm.brightness(0); // min brightness
tm.brightness(7); // max brightness