Skip to content

Commit

Permalink
Merge pull request #30 from mgesteiro/brightness
Browse files Browse the repository at this point in the history
Set default brightness
  • Loading branch information
jasonacox authored Mar 2, 2023
2 parents 0632c9b + 249f2e0 commit e8704b0
Show file tree
Hide file tree
Showing 14 changed files with 4,163 additions and 23 deletions.
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Arduino Library for the TM1637 Based LED Display Module
## Description

This is an Arduino library for 4 and 6 digit 7-segment LED display modules based on the TM1637 chip.
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.
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.

## Hardware

Expand All @@ -26,33 +26,37 @@ The display has four connectors:
* VCC - Power 5v
* GND - Ground

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.
**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.

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.
**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.

## Installation

This library is available via the Arduino IDE. Install this library via `Tools`, `Manage Libraries`, search for "TM1637TinyDisplay" and click `Install`.

Alternatively, you can install this manually by cloning this repo into your Arduino library folder (e.g. `~/Documents/Arduino/libraries`).
Alternatively, you can install this manually by cloning this repo into your Arduino library folder (e.g. `~/Documents/Arduino/libraries`).

## Example Code

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

```cpp
#include <Arduino.h>
#include <TM1637TinyDisplay.h>

// Define Digital Pins
#define CLK 1
#define DIO 2
#define CLK 2
#define DIO 3

// Instantiate TM1637TinyDisplay Class
TM1637TinyDisplay display(CLK, DIO);

void setup() {
// Initialize Display
display.begin();
display.setBrightness(BRIGHT_HIGH);
}

void loop() {
Expand Down Expand Up @@ -93,9 +97,9 @@ void loop() {
## Animation and Animator Tool
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.
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.
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:
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:
```cpp
// Data from Animator Tool
Expand Down Expand Up @@ -126,7 +130,7 @@ const uint8_t ANIMATION[12][4] = {

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

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.
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.

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

Expand All @@ -136,16 +140,14 @@ TM1637TinyDisplay6 handles this for you but you must initialize the display usin
#include <TM1637TinyDisplay6.h> // Include 6-Digit Display Class Header

// Define Digital Pins
#define CLK 1
#define DIO 2
#define CLK 2
#define DIO 3

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

void setup()
{
display.begin();
display.setBrightness(BRIGHT_HIGH);
display.clear();
display.showString("digits");
delay(1000);
display.showNumber(123456);
Expand Down Expand Up @@ -177,7 +179,7 @@ The library provides a single class named TM1637TinyDisplay with the following f
* `isflipDisplay()` - Returns orientation of the display (True = flip)
* `readBuffer(..)` - Returns current display segment values
PROGMEM functions: Large string or animation data can be left in Flash instead of being loaded in to SRAM to save memory.
PROGMEM functions: Large string or animation data can be left in Flash instead of being loaded in to SRAM to save memory.
* `showAnimation_P(..)` - Display a sequence of frames to render an animation (in PROGMEM)
* `showString_P(..)` - Display a ASCII string of text with optional scrolling for long strings (in PROGMEM)
Expand All @@ -197,4 +199,4 @@ Refer to [TM1637TinyDisplay.h](TM1637TinyDisplay.h) for information on available
* SevenSegmentTM1637 Arduino Library by Bram Harmsen - https://github.com/bremme/arduino-tm1637
* Arduino - https://playground.arduino.cc/Main/TM1637/
* MCI Electronics Datasheet for TM1637 - https://www.mcielectronics.cl/website_MCI/static/documents/Datasheet_TM1637.pdf
* 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
* 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
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for TM1637TinyDisplay

## v1.8.1 - Updated begin() method to set default brightness

* 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

## v1.8.0 - Updated library operation with new begin() method

* 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
Expand Down
1 change: 1 addition & 0 deletions TM1637TinyDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void TM1637TinyDisplay::begin()
digitalWrite(m_pinClk, LOW);
digitalWrite(m_pinDIO, LOW);
clear();
setBrightness(BRIGHT_HIGH);
}

void TM1637TinyDisplay::flipDisplay(bool flip)
Expand Down
1 change: 1 addition & 0 deletions TM1637TinyDisplay6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ void TM1637TinyDisplay6::begin()
digitalWrite(m_pinClk, LOW);
digitalWrite(m_pinDIO, LOW);
clear();
setBrightness(BRIGHT_HIGH);
}

void TM1637TinyDisplay6::flipDisplay(bool flip)
Expand Down
Binary file added examples/4-digit-display-basic.fzz
Binary file not shown.
Binary file added examples/4-digit-display-basic_bb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4,138 changes: 4,138 additions & 0 deletions examples/4-digit-display-basic_bb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion examples/ATtiny85/ATtiny85.ino
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ const PROGMEM char FlashString2[] = "good";

void setup() {
display.begin();
display.setBrightness(BRIGHT_7);
}

void loop() {
Expand Down
1 change: 0 additions & 1 deletion examples/TM1637-6Digit-Test/TM1637-6Digit-Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ TM1637TinyDisplay6 display(CLK, DIO);
void setup()
{
display.begin();
display.setBrightness(BRIGHT_HIGH);
}

void loop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ int Sec = 0;
void setup()
{
display.begin();
display.setBrightness(BRIGHT_HIGH);

pinMode(BUTTON_UP, INPUT_PULLUP);
pinMode(BUTTON_DOWN, INPUT_PULLUP);
Expand Down
1 change: 0 additions & 1 deletion examples/TM1637-Countdown/TM1637-Countdown.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ unsigned long countDown;
void setup()
{
display.begin();
display.setBrightness(BRIGHT_HIGH);

// Record Epoch - Same as Timer Reset
startTime = millis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ void setup()
{
Serial.begin(9600);
display.begin();
display.setBrightness(BRIGHT_HIGH);
AnimationNum = 0;
}

Expand Down
1 change: 0 additions & 1 deletion examples/TM1637Demo/TM1637Demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ const uint8_t ANIMATION3[218][4] PROGMEM = {

void setup() {
display.begin();
display.setBrightness(BRIGHT_7);
display.showNumber(1234);
delay(1000);

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TM1637TinyDisplay
version=1.8.0
version=1.8.1
author=Jason Cox <jason@jasonacox.com>
maintainer=Jason Cox <jason@jasonacox.com>
sentence=A simple library to display numbers, text and animation on 4 and 6 digit 7-segment TM1637 based display modules. Offers non-blocking animations and scrolling!
Expand Down

0 comments on commit e8704b0

Please sign in to comment.