Arduino library for controlling a TM163x based 7-segment display module. These modules are sold under various names by various suppliers. For example:
They come in different sizes, colors and there is a clock (with a colon) and decimal (with four decimal dots) display variant. But the most common one is the red 0.36" clock version, this is also the cheapest one (you can get those for about $1.50). I've written this library using the above module, if I get my hands on any of the other variants I might add some specific code, for example to print floats on the decimal version.
TM1637 PIN | Arduino PIN | Description |
---|---|---|
CLK | Any digital pin | Clock |
DIO | Any digital pin | Digital output |
VCC | 5V | Supply voltage |
GND | GND | Ground |
Like any other Arduino library this library is installed by copying the files into a directory on the Arduino IDE search path. Most common is to put all files in a director in your sketch folder/libraries/SevenSegmentTM1637/
. See installing additional Arduino libraries for more information.
This library uses the LCD API v1.0 so you can use the same functions/methods using this library as any lcd library which conforms to the LCD API. Furthermore this library (like described in the LCD API) inherent the Print class (See Serial.print() and for more details Print.h). This means that you can use all Print class functions/methods like you're used to when you're doing Serial.print("Something")
or Serial.print(128, BIN)
for example.
SevenSegmentTM1637(clkPin, dioPin)
Creates a display objectinit()
Initializes the displayprint(value)
Prints anything to the display (e.g. a string, number..)clear()
Clears the display (and resets cursor)home()
Resets cursorsetCursor(row, col)
Set the cursor to specified positionsetBacklight(value)
Sets the brightness of the displayon()
Turn the display on (set brightness to default)off()
Turns the display off (set brightness to zero)blink()
Blinks what ever is on the displaysetColonOn(bool)
Sets the colon in the middle of the displaysetPrintDelay(time)
Sets the delay when printing more than 4 charactersencode()
Encodes a single digit, single char or char array (C string)printRaw()
Prints raw byte(s) to the displaycommand()
Sends one or more raw byte commands to the displaycomStart()
Serial communication start commandcomWriteByte(bytes)
Serial communication send byte commandcomAck()
Serial communication get acknowledged commandcomStop()
Serial communication stop commandIf you still want or need more functionality, I've included two super classes:
SevenSegmentExtended()
Extends the base class with more usefull functions.SevenSegmentFun()
Even more extensions for fun.If you use any of these super classes, you will also get all the basic, advanced and low level methods as well. If you use the fun class extension you will get the extended class methods as well.
SevenSegmentExtended(clkPin, dioPin)
Creates a display objectprintTime(hour, min, [blink], [blinkDelay])
Prints the time to the displayprintTime(time, [blink], [blinkDelay])
Prints the time to the displayprintDualCounter(leftValue, rightValue)
Prints two digits to the displaySevenSegmentFun(clkPin, dioPin)
Creates a display objectprintLevelVertical(level, [leftToRight])
Print 0-100% (2 steps per digit) vertical level e.g. volume, batteryprintLevelVertical(level, leftToRight, symbol)
Print 0-100% (1 step per digit) vertical level using custom symbolprintLevelHorizontal(levels[])
Prints 4 horizontal levels e.g. equalizerscrollingText()
Prints text and (keeps) scrollingsnake()
Classic snake demonightrider()
Nightrider Kit demobombTimer()
Count down a (bomb) timerbouncingBall()
Bouncing ball demoFor more extended information on what arguments all above functions accept and return see the header files of the classes (SevenSegmentTM1637.h, SevenSegmentExtended.h and SevenSegmentFun.h).
printLevelVertical()
using pablo-lp suggestionsprintLevelVertical()
can diplay twice the number of levels now (e.g. 9 levels for a defaulf 4 digit display)printTime
methods (thanks to simoneluconi)printNumber()
method to make it easier to print right aligned numbersSerial.prinln()
callscomReadByte()
keywords.txt
I spend quite a bit of time to build this library. I hope it will be useful to others. I decided to publish it, although there still might be small bugs. If you find one, just let me know and I will try to fix it. If you have any other suggestion, don't hesitate to contact me.
I've looked at many sources while constructing this library, bassicly all alternative Arduino TM1637 libraries and some AVR TM1637 libraries. While doing so I've found some really nice improvements compared to other implementations. For example, most libraries use a really low clock speed (~50us), I've tested with clock speeds as low as 1us and the chip still seems to respond well. Furthermore, from the (Chinese) datasheet it seems that you always have to perform three operation when communicating with the IC; set some configuration, set the address and send 1-4 digit data and set the display brightness. I've found out that this is not the case, you can do all of those separately if you want.
Still without all these fine examples it would have taken me a lot more time to figure out the inner workings of this IC!
Sources:
People will probably Google for keywords when looking for a driver, so here are some:
TM1637 TM1636 library Arduino Led Driver 4 Digit Bits Digital LED Tube module LCD API Print.h Print class API display LCD AVR Atmega