Led7Segment
An Arduino library for 7-segment display modules based on the TM1637 chip.
The library is based on TM1637Display (https://github.com/avishorp/TM1637): it retains the original low-level functions for communication with the TM1637 chip, but replaces or enhances the public methods.
Hardware Connection
The display module has signal connections CLK and DIO (besides power connections). These pins can be connected to any pair of digital pins on the Arduino. There is no limitation on the number of instances used concurrently (as long as each instance has a pin pair of its own).
Installation
Download the .zip file and install it using Sketch / Include Library / Add .ZIP Library in Arduino IDE. Alternatively, unzip the archive into directory sketches/libraries.
Usage
The library provides a class named Led7Segment with the following methods.
- Led7Segment(pinClk, pinDio)
- Initialize the display, enable it and set it to the highest brightness.
- turnOn()
- Turn the display on.
- turnOff()
- Turn the display off.
- setBrightness(brightness)
- Set the brightness (0 - 7). The change takes effect immediately.
- clearDisplay(pos=0, length=4, zeros=false)
- Clear the display or a part of a given
lengthstarting frompos(0 is the leftmost digit). Ifzerosis set totrue, the display is filled with zeros instead of with blanks. - showNumber(number, pos=0, length=4, leading_zeros=false, base=10)
- Show
numstarting atpos(0 being the left-most digit) and usinglengthdigits. The number is right-aligned; ifleading_zerosis set totrue, the number is left-padded with zeros. If pos + length >= 4, length is decreased accordingly.If the number (including the minus sign, when needed) does not fit into
length, E's are shown instead of the number. - setDots(mask)
- Set dots at the places corresponding to the four right-most bits.
For displays with a single colon at the middle,
setDots(4)shows the colon andsetDots(0)hides it. - setSegments(data[], pos, length)
- Set
lengthdigits starting fromposwith the givendata, which contains one byte per digit, with one bit per segment. The library defines constantsSEG_T,SEG_TR,SEG_BR,SEG_B,SEG_BL,SEG_TL,SEG_MandSEG_Dwith values 1, 2, 4, 8, ... 128 which correspond to bits representing the top, top-right, bottom-right, bottom, bottom-left, top-left, middle segment, and the dot, respectively. E.g.donEcan be shown withsetSegment(done);wheredoneisuint8_t done[] = { SEG_TR | SEG_BR | SEG_B | SEG_BL | SEG_M, // d SEG_BR | SEG_B | SEG_BL | SEG_M, // o SEG_BR | SEG_BL | SEG_M, // n SEG_TL | SEG_BL | SEG_T | SEG_M | SEG_B // E };
Base must be between 2 (binary) and 16 (hexadecimal).