An Arduino library for interfacing tot he TM6138 LED and Keypad controller IC.
This library provides an easy way to interface tot he TM6138 IC from your Arduino giving full control over the drivers LED outputs and allowing for reading of the status of a connected keypad. The library has additional functions written specifically for our 8 digit seven segment display and keypad module (HCMODU0095) available from out online store here:
[LINK TBA]
You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area.
On Windows:
My Documents\Arduino\libraries\
On Mac:
Docments/Arduino/libraries/
or similarly for Linux.
Using the library
To use the library just include the HCTM1638.h header file and then create an instance of the library. E.g:
Code: Select all
#include <HCTM1638.h>
HCTM1638 HCTM1638(STB, DIO, CLK);
STB is the digital pin used to interface to the TM1638's strobe pin.
DIO is the digital pin used to interface to the TM1638's data in/out pin.
CLKis the digital pin used to interface to the TM1638's clock pin.
The following functions are available with this library:
Code: Select all
HCTM1638.Brightness(Value);
Value is the brightness of all LED segments. Valid values are from 0 (min) to 8 (max).
Code: Select all
HCTM1638.Disp_ON();
Code: Select all
HCTM1638.Disp_OFF();
Code: Select all
HCTM1638.SendByte(Data);
Data is the data of type byte to be send to the TM1638.
Code: Select all
HCTM1638.Clear();
Code: Select all
HCTM1638.WriteDispMem(Address, Data);
Address is the memory location address. Valid values are from 0x00 to 0x0F
Data is the byte of data to be written.
HCMODU0095 specific functions:
Code: Select all
HCTM1638.SetDigit(Digit, Value);
Digit is the one of the 8 digits on the display. Valid values are from 1 to 8.
Value is the raw byte value to write.
Code: Select all
HCTM1638.SetLED(Led, Value);
Led is which LED to control. Valid values are from 1 to 8.
Value is the raw byte value to write. A value of 0 will turn off the LED and a value of 1 will turn it on.
Code: Select all
HCTM1638.ReadButtons();
Returns the state of one of the 8 push buttons where:State = HCTM1638.ButtonState(Button);
Button is the button to check. Valid values are:
BUTTON1
BUTTON2
BUTTON3
BUTTON4
BUTTON5
BUTTON6
BUTTON7
Returns a Boolean value where false = not pressed and true = pressed
Code: Select all
HCTM1638.print7Seg(Text, Offset, DP);
Text is a quoted string of text or null terminated character array of ASCII text to display.
Offset is the position on the display to start displaying the text from. Where 1 is the right most and 8 is the left most digit on the display. Text can also be positioned off screen. I.e. a value of 0 will position the text to the right of the display, a value > 8 will position the text to the left of the display.
DP is an optional decimal point specifier. If false any decimal points will use one digit of the display. If true decimal points will be displayed on the same digit as the previous alphanumeric character.
Code: Select all
HCTM1638.print7Seg(Value, Offset, DecimalPlaces);
Value is the signed floating point number to display
Offset is the position on the display to start displaying the value from. Where 1 is the right most and 8 is the left most digit on the display. Text can also be positioned off screen. I.e. a value of 0 will position the text to the right of the display, a value > 8 will position the text to the left of the display.
DecimalPlaces is optional and sets number of decimal places to display the number to.
Code: Select all
/* FILE: HCMODU0095_Text_And_Numbers.cpp
DATE: 21/01/16
VERSION: 0.1
AUTHOR: Andrew Davies
21/01/16 version 0.1: Original version
This sketch demonstrates the use of the HCTM1638 library with the Hobby
Components TM1638 Serial Seven Segment Display & Keypad (HCMODU0095) to
display some text and numbers.
Connect the module to your Arduino as follows:
Module.....Arduino
VCC........+5V
GND........GND
STB........Digital pin 7
CLK........Digital pin 8
DIO........Digital pin 9
You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/
/* Include the library */
#include "HCTM1638.h"
/* Set the digital pins used to interface to the module */
#define STB 7 // Strobe pin
#define CLK 8 // Clock pin
#define DIO 9 // Data pin
/* Create an instance of the library */
HCTM1638 HCTM1638(STB, DIO, CLK);
void setup()
{
/* Set the LED display brightness to maximum */
HCTM1638.Brightness(0x07);
}
void loop()
{
/* Display some text starting at position 8 */
HCTM1638.print7Seg("HELLO !!", 8);
delay(2000);
HCTM1638.Clear();
/* Display a integer number starting at position 6*/
HCTM1638.print7Seg(1234, 6);
delay(2000);
HCTM1638.Clear();
/* Display a decimal number starting at position 7 with 3 decimal places */
HCTM1638.print7Seg(-12.345, 7, 3);
delay(2000);
HCTM1638.Clear();
/* Display a decimal number starting at position 7 cropped to 1 decimal place */
HCTM1638.print7Seg(-12.345, 7, 1);
delay(2000);
}
The HCTM1638 library can be downloaded here (please log in to download):