Skip to content

Commit 6fbf240

Browse files
authored
Merge pull request #2 from jasonacox/master
Updates my branch
2 parents e38e84f + f32a6b5 commit 6fbf240

18 files changed

+4253
-71
lines changed

README.md

Lines changed: 64 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
# TM1637 Tiny Display #
1+
# TM1637 Tiny Display
2+
23
[![arduino-library-badge](https://www.ardu-badge.com/badge/TM1637TinyDisplay.svg?)](https://www.ardu-badge.com/TM1637TinyDisplay)
34
[![Build Status](https://github.com/jasonacox/TM1637TinyDisplay/actions/workflows/sketch.yml/badge.svg)](https://github.com/jasonacox/TM1637TinyDisplay/actions/workflows/sketch.yml)
45

56
Arduino Library for the TM1637 Based LED Display Module
67

78
## Description
9+
810
This is an Arduino library for 4 and 6 digit 7-segment LED display modules based on the TM1637 chip.
9-
Connect the TM1637 display CLK and DIO pins to your Arduino GPIO pins, include this library, initialize TM1637TinyDisplay and call easy to use functions like showNumber(), showString(), showLevel() and showAnimation(). Display will scroll text for larger strings. Functions support screen splitting for easy number + text formatting. Library also runs well on tiny controllers including the ATtiny85.
11+
Connect the TM1637 display CLK and DIO pins to your Arduino GPIO pins, include this library, initialize TM1637TinyDisplay and call easy to use functions like `showNumber()`, `showString()`, `showLevel()` and `showAnimation()`. Display will scroll text for larger strings. Functions support screen splitting for easy number + text formatting. Library also runs well on tiny controllers including the ATtiny85.
12+
13+
## Hardware
1014

11-
## Hardware
1215
![TM1637](examples/tm1637.png)
1316

1417
* 4-Digit Display modules based on the TM1637 chip are available from [HiLetgo](https://www.amazon.com/gp/product/B01DKISMXK/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1), [DX](https://dx.com/p/0-36-led-4-digit-display-module-for-arduino-black-blue-works-with-official-arduino-boards-254978) and [SeeedStudio](https://www.digikey.com/products/en?keywords=tm1637).
@@ -17,62 +20,43 @@ Connect the TM1637 display CLK and DIO pins to your Arduino GPIO pins, include t
1720
![TM1637](examples/tm1637back.png)
1821

1922
The display has four connectors:
20-
* CLK - Clock - attach to any GPIO output
21-
* DIO - Data - attach to any GPIO output
23+
24+
* CLK - Clock - attach to any GPIO output
25+
* DIO - Data - attach to any GPIO output
2226
* VCC - Power 5v
2327
* GND - Ground
2428

25-
Power Note: Steady clean power is important for circuit stability. If you are seeing display artifacts during high frequency updates or animation sequences, you may be experiencing power fluctuations that are impacting signal timing and communication with the TM1637. This is especially true with standalone microprocessor applications that lack any power conditioning (e.g. ATtiny85). A polarized 100uF electrolytic capacitor inserted across VCC and GND can help smooth out the spikes.
29+
**Power Note:** Steady clean power is important for circuit stability. If you are seeing display artifacts during high frequency updates or animation sequences, you may be experiencing power fluctuations that are impacting signal timing and communication with the TM1637. This is especially true with standalone microprocessor applications that lack any power conditioning (e.g. ATtiny85). A polarized 100uF electrolytic capacitor inserted across VCC and GND can help smooth out the spikes.
2630

27-
Decimals and Colons: Some TM1637 displays come equipped with a middle colon LED (as shown above) as used in digital clocks but with no decimal points. Some displays come with decimal point LEDS for each digit. Some come with both but often the decimal point LEDs are not connected. These extra LEDs are activated by setting the upper bit (0x80) for the digit next to the dot. This library will handle setting that for you via the showNumber() function when you specify floating point numbers or via the showNumberDec() function where you can set the decimal point manually.
31+
**Decimals and Colons:** Some TM1637 displays come equipped with a middle colon LED (like above) as used in digital clocks but with no decimal points. Some displays come with decimal point LEDS for each digit. Some come with both but often the decimal point LEDs are not connected. These extra LEDs are activated by setting the upper eighth bit (0x80) for the digit to the left of the dot. This library will handle setting that for you via the `showNumber()` function when you specify floating point numbers, or you can do it manually via the `showNumberDec()` function where you can set the decimal points/colon yourself.
2832

2933
## Installation
30-
This library is available via the Arduino IDE. Install this library via `Tools`, `Manage Libraries`, search for "TM1637TinyDisplay" and click `Install`.
31-
32-
Alternatively, you can install this manually by cloning this repo into your Arduino library folder (e.g. `~/Documents/Arduino/libraries`).
3334

34-
## Usage
35-
The library provides a single class named TM1637TinyDisplay with the following functions:
36-
37-
* `showNumber` - Display an integer and floating point numbers (positive or negative)
38-
* `showNumberDec` - Display a number with ability to manually set decimal points or colon
39-
* `showNumberHex` - Display a number in hexadecimal format and set decimal point or colon
40-
* `showString` - Display a ASCII string of text with optional scrolling for long strings
41-
* `showLevel` - Use display LEDs to simulate a level indicator (vertical or horizontal)
42-
* `showAnimation` - Display a sequence of frames to render an animation
43-
* `startAnimation` - Begins a non-blocking animation of a sequence of frames
44-
* `startStringScroll` - Begins a non-blocking scrolling of a string message
45-
* `Animate` - Worker routine to be called regularly which handles animations and scrolling in a non-blocking manner
46-
* `setSegments` - Directly set the value of the LED segments in each digit
47-
* `setBrightness` - Sets the brightness of the display
48-
* `setScrolldelay` - Sets the speed for text scrolling
49-
* `flipDisplay` - Sets/flips the orientation of the display
50-
* `isflipDisplay` - Returns orientation of the display (True = flip)
51-
* `readBuffer` - Returns current display segment values
52-
53-
PROGMEM functions: Large string or animation data can be left in Flash instead of being loaded in to SRAM to save memory.
35+
This library is available via the Arduino IDE. Install this library via `Tools`, `Manage Libraries`, search for "TM1637TinyDisplay" and click `Install`.
5436

55-
* `showAnimation_P` - Display a sequence of frames to render an animation (in PROGMEM)
56-
* `showString_P` - Display a ASCII string of text with optional scrolling for long strings (in PROGMEM)
57-
* `startAnimation_P` - Begins a non-blocking animation of a sequence of frames stored in PROGMEM
58-
* `startStringScroll_P` - Begins a non-blocking scrolling of a string message stored in PROGMEM
37+
Alternatively, you can install this manually by cloning this repo into your Arduino library folder (e.g. `~/Documents/Arduino/libraries`).
5938

39+
## Example Code
6040

41+
<p align="center">
42+
<a href="examples/4-digit-display-basic.fzz"><img src="examples/4-digit-display-basic_bb.svg" width="40%" /></a><br />
43+
Basic connection schematic done with <a href="https://fritzing.org">Fritzing</a>
44+
</p>
6145

62-
## Example Code
6346
```cpp
6447
#include <Arduino.h>
6548
#include <TM1637TinyDisplay.h>
6649

6750
// Define Digital Pins
68-
#define CLK 1
69-
#define DIO 2
51+
#define CLK 2
52+
#define DIO 3
7053

71-
// Initialize TM1637TinyDisplay
54+
// Instantiate TM1637TinyDisplay Class
7255
TM1637TinyDisplay display(CLK, DIO);
7356

7457
void setup() {
75-
display.setBrightness(0x0f);
58+
// Initialize Display
59+
display.begin();
7660
}
7761

7862
void loop() {
@@ -111,12 +95,11 @@ void loop() {
11195
}
11296
```
11397
114-
Refer to [TM1637TinyDisplay.h](TM1637TinyDisplay.h) for information on available functions. See also [Examples](examples) for more demonstration.
115-
11698
## Animation and Animator Tool
117-
The showAnimation() function projects a sequence of frames (patterns) onto the display. This works by defining the animation sequence through a multi-dimensional array of patterns.
11899
119-
You can use the included javascript based interactive [7-Segment LED Animator Tool](https://jasonacox.github.io/TM1637TinyDisplay/examples/7-segment-animator.html) to help build your animation. The source code is in the [Examples](examples) folder. This tool will let you set up the LED sequences you want, save each frame and copy the final code (a static array) directly into your sketch to use for the `showAnimation(data, frames, timing)` function. Here is an example:
100+
The `showAnimation()` function projects a sequence of frames (patterns) onto the display. This works by defining the animation sequence through a multi-dimensional array of patterns.
101+
102+
You can use the included javascript based interactive [7-Segment LED Animator Tool](https://jasonacox.github.io/TM1637TinyDisplay/examples/7-segment-animator.html) to help build your animation. The source code is in the [Examples](examples) folder. This tool will let you set up the LED sequences you want, save each frame and copy the final code (a static array) directly into your sketch to use for the `showAnimation(data, frames, timing)` function. Here is an example:
120103
121104
```cpp
122105
// Data from Animator Tool
@@ -147,7 +130,7 @@ const uint8_t ANIMATION[12][4] = {
147130

148131
![TM1637-6-Back](examples/tm1637-6-back.png)
149132

150-
This library now supports the 6-digit display as well as the 4-digit display. The 6-digit display requires additional handling. Specifically, the display digits are not sequential (requires a map) and the 7-segment LED data must be uploaded in reverse order.
133+
This library now supports the 6-digit display as well as the 4-digit display. The 6-digit display requires additional handling. Specifically, the display digits are not sequential (requires a map) and the 7-segment LED data must be uploaded in reverse order.
151134

152135
TM1637TinyDisplay6 handles this for you but you must initialize the display using the TM1637TinyDisplay6 class:
153136

@@ -157,15 +140,14 @@ TM1637TinyDisplay6 handles this for you but you must initialize the display usin
157140
#include <TM1637TinyDisplay6.h> // Include 6-Digit Display Class Header
158141

159142
// Define Digital Pins
160-
#define CLK 1
161-
#define DIO 2
143+
#define CLK 2
144+
#define DIO 3
162145

163146
TM1637TinyDisplay6 display(CLK, DIO); // 6-Digit Display Class
164147

165148
void setup()
166149
{
167-
display.setBrightness(BRIGHT_HIGH);
168-
display.clear();
150+
display.begin();
169151
display.showString("digits");
170152
delay(1000);
171153
display.showNumber(123456);
@@ -175,13 +157,46 @@ void setup()
175157
}
176158
```
177159
160+
## Functions
161+
162+
The library provides a single class named TM1637TinyDisplay with the following functions:
163+
164+
* `begin()` - Initialize display memory and hardware (call in `setup()`)
165+
* `clear()` - Display an integer and floating point numbers (positive or negative)
166+
* `showNumber(..)` - Display a number
167+
* `showNumberDec(..)` - Display a number with ability to manually set decimal points or colon
168+
* `showNumberHex(..)` - Display a number in hexadecimal format and set decimal point or colon
169+
* `showString(..)` - Display a ASCII string of text with optional scrolling for long strings
170+
* `startStringScroll(..)` - Begins a non-blocking scrolling of a string message
171+
* `showLevel(..)` - Use display LEDs to simulate a level indicator (vertical or horizontal)
172+
* `showAnimation(..)` - Display a sequence of frames to render an animation
173+
* `startAnimation(..)` - Begins a non-blocking animation of a sequence of frames
174+
* `Animate()` - Worker routine to be called regularly which handles animations and scrolling in a non-blocking manner
175+
* `setSegments(..)` - Directly set the value of the LED segments in each digit
176+
* `setBrightness(..)` - Sets the brightness of the display
177+
* `setScrolldelay(..)` - Sets the speed for text scrolling
178+
* `flipDisplay(..)` - Sets/flips the orientation of the display
179+
* `isflipDisplay()` - Returns orientation of the display (True = flip)
180+
* `readBuffer(..)` - Returns current display segment values
181+
182+
PROGMEM functions: Large string or animation data can be left in Flash instead of being loaded in to SRAM to save memory.
183+
184+
* `showAnimation_P(..)` - Display a sequence of frames to render an animation (in PROGMEM)
185+
* `showString_P(..)` - Display a ASCII string of text with optional scrolling for long strings (in PROGMEM)
186+
* `startAnimation_P(..)` - Begins a non-blocking animation of a sequence of frames stored in PROGMEM
187+
* `startStringScroll_P(..)` - Begins a non-blocking scrolling of a string message stored in PROGMEM
188+
189+
Refer to [TM1637TinyDisplay.h](TM1637TinyDisplay.h) for information on available functions. See also [Examples](examples) for more demonstration.
190+
178191
## Arduino Library
192+
179193
* Library: https://www.arduinolibraries.info/libraries/tm1637-tiny-display
180194
* Scan Logs: http://downloads.arduino.cc/libraries/logs/github.com/jasonacox/TM1637TinyDisplay/
181195
182196
## References and Credit
197+
183198
* This library is based on the great work by Avishay Orpaz - https://github.com/avishorp/TM1637
184199
* SevenSegmentTM1637 Arduino Library by Bram Harmsen - https://github.com/bremme/arduino-tm1637
185200
* Arduino - https://playground.arduino.cc/Main/TM1637/
186201
* MCI Electronics Datasheet for TM1637 - https://www.mcielectronics.cl/website_MCI/static/documents/Datasheet_TM1637.pdf
187-
* TM16xx - Library for entire TM16xx chip family include maxint-rd's own [display-modules](https://github.com/maxint-rd/arduino-modules#display-modules) - https://github.com/maxint-rd/TM16xx
202+
* TM16xx - Library for entire TM16xx chip family include maxint-rd's own [display-modules](https://github.com/maxint-rd/arduino-modules#display-modules) - https://github.com/maxint-rd/TM16xx

RELEASE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Release Notes for TM1637TinyDisplay
22

3+
## v1.8.1 - Add Default Brightness
4+
5+
* Updated the `begin()` method to set a non zero default brightness for the display, as reported in https://github.com/jasonacox/TM1637TinyDisplay/pull/29#issuecomment-1446362105 and submitted by @mgesteiro in https://github.com/jasonacox/TM1637TinyDisplay/pull/30
6+
7+
## v1.8.0 - Updated Library Operation with New begin() Method
8+
9+
* Updated library operation to include an initializing method `begin()` to move outside the constructor hardware related calls, as reported in https://github.com/jasonacox/TM1637TinyDisplay/issues/28
10+
11+
## v1.7.1 - Fix Compile Errors for ESP8266
12+
13+
* Fix compile errors and warnings on ESP8266 cores (type casts and erroneous defaults in functions) as reported in https://github.com/jasonacox/TM1637TinyDisplay/issues/26
14+
* Fix function names for async animation/scroll in keywords.txt by @hackerceo in https://github.com/jasonacox/TM1637TinyDisplay/pull/25
15+
316
## v1.7.0 - Add Non-Blocking Animation for 4-Digit
417

518
* Add non-blocking animation and string scrolling to 4-digit display by @hackerceo in https://github.com/jasonacox/TM1637TinyDisplay/pull/24

TM1637TinyDisplay.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,18 @@ TM1637TinyDisplay::TM1637TinyDisplay(uint8_t pinClk, uint8_t pinDIO, unsigned in
172172
m_scrollDelay = scrollDelay;
173173
// Flip
174174
m_flipDisplay = flip;
175-
175+
}
176+
177+
void TM1637TinyDisplay::begin()
178+
{
176179
// Set the pin direction and default value.
177180
// Both pins are set as inputs, allowing the pull-up resistors to pull them up
178181
pinMode(m_pinClk, INPUT);
179182
pinMode(m_pinDIO, INPUT);
180183
digitalWrite(m_pinClk, LOW);
181184
digitalWrite(m_pinDIO, LOW);
182185
clear();
186+
setBrightness(BRIGHT_HIGH);
183187
}
184188

185189
void TM1637TinyDisplay::flipDisplay(bool flip)
@@ -638,17 +642,17 @@ void TM1637TinyDisplay::startAnimation(const uint8_t (*data)[MAXDIGITS], unsigne
638642
m_animation_start = millis() ;
639643
m_animation_frames = frames;
640644
m_animation_frame_ms = ms;
641-
m_animation_sequence = data;
645+
m_animation_sequence = (uint8_t (*)[MAXDIGITS]) data;
642646
m_animation_string = nullptr;
643647
}
644648

645649

646-
void TM1637TinyDisplay::startStringScroll_P(const char s[], unsigned int ms)
650+
void TM1637TinyDisplay::startStringScroll_P(const char s[], unsigned int ms)
647651
{
648652
startStringScroll(s, ms, true);
649653
}
650654

651-
void TM1637TinyDisplay::startStringScroll(const char (*s), unsigned int ms, bool usePROGMEM = false) {
655+
void TM1637TinyDisplay::startStringScroll(const char s[], unsigned int ms, bool usePROGMEM) {
652656
if (usePROGMEM) {
653657
m_animation_frames = strlen_P(s);
654658
if (m_animation_frames <= MAXDIGITS) {
@@ -674,7 +678,7 @@ void TM1637TinyDisplay::startStringScroll(const char (*s), unsigned int ms, bool
674678
m_animation_start = millis();
675679
m_animation_frame_ms = ms;
676680
m_animation_sequence = nullptr;
677-
m_animation_string = s;
681+
m_animation_string = (uint8_t *) s;
678682
}
679683

680684

TM1637TinyDisplay.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@
117117
class TM1637TinyDisplay {
118118

119119
public:
120-
//! Initialize a TM1637TinyDisplay object, setting the clock and
121-
//! data pins.
120+
//! Initialize a TM1637TinyDisplay object.
122121
//!
123122
//! @param pinClk - The number of the digital pin connected to the clock pin of the module
124123
//! @param pinDIO - The number of the digital pin connected to the DIO pin of the module
@@ -128,6 +127,12 @@ class TM1637TinyDisplay {
128127
TM1637TinyDisplay(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay = DEFAULT_BIT_DELAY,
129128
unsigned int scrollDelay = DEFAULT_SCROLL_DELAY, bool flip=DEFAULT_FLIP);
130129

130+
//! Initialize the display, setting the clock and data pins.
131+
//!
132+
//! This method should be called once (typically in setup()) before calling any other.
133+
//! @note It may be unnecessary depending on your hardware configuration.
134+
void begin();
135+
131136
//! Sets the orientation of the display.
132137
//!
133138
//! Setting this parameter to true will cause the rendering on digits to be displayed
@@ -475,7 +480,7 @@ class TM1637TinyDisplay {
475480
unsigned int m_animation_frames;
476481
unsigned int m_animation_last_frame;
477482
unsigned int m_animation_frame_ms;
478-
uint8_t (*m_animation_sequence)[4];
483+
uint8_t (*m_animation_sequence)[MAXDIGITS];
479484
uint8_t (*m_animation_string);
480485
uint8_t m_animation_type;
481486
};

TM1637TinyDisplay6.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,18 @@ TM1637TinyDisplay6::TM1637TinyDisplay6(uint8_t pinClk, uint8_t pinDIO,
174174
m_scrollDelay = scrollDelay;
175175
// Flip
176176
m_flipDisplay = flip;
177-
177+
}
178+
179+
void TM1637TinyDisplay6::begin()
180+
{
178181
// Set the pin direction and default value.
179182
// Both pins are set as inputs, allowing the pull-up resistors to pull them up
180183
pinMode(m_pinClk, INPUT);
181184
pinMode(m_pinDIO, INPUT);
182185
digitalWrite(m_pinClk, LOW);
183186
digitalWrite(m_pinDIO, LOW);
184187
clear();
188+
setBrightness(BRIGHT_HIGH);
185189
}
186190

187191
void TM1637TinyDisplay6::flipDisplay(bool flip)

TM1637TinyDisplay6.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@
117117
class TM1637TinyDisplay6 {
118118

119119
public:
120-
//! Initialize a TM1637TinyDisplay object, setting the clock and
121-
//! data pins.
120+
//! Initialize a TM1637TinyDisplay object.
122121
//!
123122
//! @param pinClk - The number of the digital pin connected to the clock pin of the module
124123
//! @param pinDIO - The number of the digital pin connected to the DIO pin of the module
@@ -128,6 +127,12 @@ class TM1637TinyDisplay6 {
128127
TM1637TinyDisplay6(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay = DEFAULT_BIT_DELAY,
129128
unsigned int scrollDelay = DEFAULT_SCROLL_DELAY, bool flip=DEFAULT_FLIP);
130129

130+
//! Initialize the display, setting the clock and data pins.
131+
//!
132+
//! This method should be called once (typically in setup()) before calling any other.
133+
//! @note It may be unnecessary depending on your hardware configuration.
134+
void begin();
135+
131136
//! Sets the orientation of the display.
132137
//!
133138
//! Setting this parameter to true will cause the rendering on digits to be displayed

examples/4-digit-display-basic.fzz

16.7 KB
Binary file not shown.

examples/4-digit-display-basic_bb.png

98.8 KB
Loading

0 commit comments

Comments
 (0)