Skip to content

lib_tm1638: 8 digit LED and keypad controller

Richard Hodges edited this page Oct 23, 2018 · 2 revisions

These boards are an easy way to get an 8 digit display and a keypad in a cheap and convenient package.

To use this library, include the header file "lib_tm1638.h" with your #include files and call tm1638_init(mode) with either TM1638_8 or TM1638_16 for the board you have.

8 key keypad 16 key keypad

Use tm1638_putc(char) to send a single char to the display or tm1638_puts(string) to send a string. For the decimal point, set bit-7 if you are sending one char at a time. For strings, just put the decimal place where you want it to appear.

tm1638_putc(char); /* send one char */
tm1638_puts(char *); /* send string */
tm1638_curs(char); /* sets the cursor position (0-7). */
tm1638_clear(void); /* clear the display. */
tm1638_bright(char); /* sets the brightness (0-7). */
tm1638_blink(char); /* set the blink rate. The rate is times 1/100 second, or 0 to disable. */
tm1638_setled(char, char); /* turns an LED on or off. This is only available on the 8-key boards. */
tm1638_push(void); /* push display changes to LEDs (16 key only) */

tm1638_poll(void); /* poll for keypress */
tm1638_getc(void); /* get key press */
tm1638_kmap(char *); /* install custom key map */

On the 16-key boards, call tm1638_push()to push display changes to the LEDs. The LEDs are not updated until this call.

The 7-segment display can handle the ASCII digits (of course), space, hyphen, and the letters "ABCDEFHJLOPSU".

To get key presses, call tm1638_poll() every millisecond. This is easy when you use the millisecond callback in my "lib_clock" library. Then periodically call tm1638_getc() to harvest key presses. Bit-7 will be low for a key press and high for release. You can use this to create shift function keys. The key values will be the ASCII characters "01234567" for the 8 key board and ""0123456789ABCDEF" for the 16-key board. This is the default: you can change this and set your own key map with tm1638_kmap().