Skip to content

Commit

Permalink
Add animation looping option
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed Apr 16, 2023
1 parent 815eb23 commit a7faa90
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ The library provides a single class named TM1637TinyDisplay with the following f
* `showAnimation(..)` - Display a sequence of frames to render an animation
* `startAnimation(..)` - Begins a non-blocking animation of a sequence of frames
* `Animate()` - Worker routine to be called regularly which handles animations and scrolling in a non-blocking manner
* `stopAnimation(..)` - Stops non-blocking animation
* `setSegments(..)` - Directly set the value of the LED segments in each digit
* `setBrightness(..)` - Sets the brightness of the display
* `setScrolldelay(..)` - Sets the speed for text scrolling
Expand Down
20 changes: 18 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
# Release Notes for TM1637TinyDisplay

## v1.9.1 - Overflow Fix for showNumber()
## v1.10.0 - Animation Looping

* Changed abs() to labs() in showNumber() function by @KelevraSlevin7 in https://github.com/jasonacox/TM1637TinyDisplay/pull/33
* Bug Fix (v1.9.1): Changed abs() to labs() in showNumber() function by @KelevraSlevin7 in https://github.com/jasonacox/TM1637TinyDisplay/pull/33 fixes overflow situation on some cores for showNumber()
* Added option for non-blocking animation to allow looping sequence via `Animate(true)` and added method to stop animation with `stopAnimation()` for `TM1637TinyDisplay` and `TM1637TinyDisplay6` classes.

```cpp
//! The event loop function to enable non-blocking animations
//!
//! The method returns TRUE when an animation is still occurring, it is
//! FALSE when there is no animation occurring
//!
//! @return A boolean value indicating if an animation is occurring
//! @param loop If true, keep looping animation when it ends
bool Animate(bool loop = false);

//! The function used to stop a non-blocking animation
//!
void stopAnimation();
```
## v1.9.0 - Add Non-Blocking Animation for 6-Digit
Expand Down
12 changes: 11 additions & 1 deletion TM1637TinyDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ void TM1637TinyDisplay::showLevel(unsigned int level, bool horizontal)
setSegments(digits);
}

bool TM1637TinyDisplay::Animate()
bool TM1637TinyDisplay::Animate(bool loop)
{
// return if no animation/scroll is running
if (m_animation_type == 0) return false;
Expand All @@ -577,8 +577,14 @@ bool TM1637TinyDisplay::Animate()

// we have run past our max frame (this can happen because of frame dropping)
if (frame_num >= m_animation_frames) {
if (loop) {
// restart
m_animation_start = millis();
frame_num = 0;
} else {
m_animation_type = 0;
return false;
}
}

// bail out if the animation frame has not changed
Expand Down Expand Up @@ -647,6 +653,10 @@ void TM1637TinyDisplay::startAnimation(const uint8_t (*data)[MAXDIGITS], unsigne
m_animation_string = nullptr;
}

void TM1637TinyDisplay::stopAnimation()
{
m_animation_type = 0;
}

void TM1637TinyDisplay::startStringScroll_P(const char s[], unsigned int ms)
{
Expand Down
24 changes: 12 additions & 12 deletions TM1637TinyDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,15 @@ class TM1637TinyDisplay {

//! Display a Level Indicator (both orientations)
//!
//! Illumiate LEDs to provide a visual indicator of level (horizontal or vertical orientation)
//! Illuminate LEDs to provide a visual indicator of level (horizontal or vertical orientation)
//!
//! @param level A value between 0 and 100 (representing percentage)
//! @param horizontal Boolean (true/false) where true = horizontal, false = vertical
void showLevel(unsigned int level = 100, bool horizontal = true);

//! Display a sequence of raw LED segment data to create an animation
//!
//! Play thorugh an array of raw LED segment data to create a moving pattern.
//! Play through an array of raw LED segment data to create a moving pattern.
//!
//! const uint8_t Example[2][4] =
//! {
Expand All @@ -391,7 +391,7 @@ class TM1637TinyDisplay {

//! Display a sequence of raw LED segment data to create an animation (PROGMEM)
//!
//! Play thorugh an array of raw LED segment data to create a moving pattern.
//! Play through an array of raw LED segment data to create a moving pattern.
//! This function is for reading PROGMEM read-only flash memory space instead of RAM
//!
//! const uint8_t Example[2][4] =
Expand All @@ -414,15 +414,14 @@ class TM1637TinyDisplay {
//! @param ms Time to delay between each frame
void showAnimation_P(const uint8_t data[][4], unsigned int frames = 0, unsigned int ms = 10);


//! The event loop function to enable non-blocking animations
//!
//! The method does not take any input parameters and returns a boolean
//! The return value is TRUE when an animation is still occuring, it is
//! FALSE when there is no animiation occuring
//! The method returns TRUE when an animation is still occurring, it is
//! FALSE when there is no animation occurring
//!
//! @return A boolean value indicating if an animation is occuring
bool Animate();
//! @return A boolean value indicating if an animation is occurring
//! @param loop If true, keep looping animation when it ends
bool Animate(bool loop = false);

//! The function used to begin a non-blocking animation
//!
Expand All @@ -432,15 +431,17 @@ class TM1637TinyDisplay {
void startAnimation(const uint8_t (*data)[MAXDIGITS], unsigned int frames = 0, unsigned int ms = 10, bool usePROGMEM = false);
void startAnimation_P(const uint8_t(*data)[MAXDIGITS], unsigned int frames = 0, unsigned int ms = 10);

//! The function used to stop a non-blocking animation
//!
void stopAnimation();

//! The function used to begin a non-blocking scroll of a string
//!
//! @param usePROGMEN Indicates if the passed string data is coming from a PROGMEM defined variable
//! @param ms Time to delay between each frame
void startStringScroll(const char s[], unsigned int ms = DEFAULT_SCROLL_DELAY, bool usePROGMEM = false);
void startStringScroll_P(const char s[], unsigned int ms = DEFAULT_SCROLL_DELAY);



//! Translate a single ASCII character into 7 segment code
//!
//! The method accepts a number between 0 - 255 and converts it to the
Expand All @@ -452,7 +453,6 @@ class TM1637TinyDisplay {
//! bit 6 - segment G; bit 7 - always zero)
uint8_t encodeASCII(uint8_t chr);


protected:
void bitDelay();

Expand Down
12 changes: 11 additions & 1 deletion TM1637TinyDisplay6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ void TM1637TinyDisplay6::showLevel(unsigned int level, bool horizontal)
setSegments(digits);
}

bool TM1637TinyDisplay6::Animate()
bool TM1637TinyDisplay6::Animate(bool loop)
{
// return if no animation/scroll is running
if (m_animation_type == 0) return false;
Expand All @@ -580,8 +580,14 @@ bool TM1637TinyDisplay6::Animate()

// we have run past our max frame (this can happen because of frame dropping)
if (frame_num >= m_animation_frames) {
if (loop) {
// restart
m_animation_start = millis();
frame_num = 0;
} else {
m_animation_type = 0;
return false;
}
}

// bail out if the animation frame has not changed
Expand Down Expand Up @@ -650,6 +656,10 @@ void TM1637TinyDisplay6::startAnimation(const uint8_t (*data)[MAXDIGITS], unsign
m_animation_string = nullptr;
}

void TM1637TinyDisplay6::stopAnimation()
{
m_animation_type = 0;
}

void TM1637TinyDisplay6::startStringScroll_P(const char s[], unsigned int ms)
{
Expand Down
24 changes: 11 additions & 13 deletions TM1637TinyDisplay6.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ class TM1637TinyDisplay6 {
//! @param pos The position of the most significant digit (0 - leftmost, 5 - rightmost)
void showNumber(int num, bool leading_zero = false, uint8_t length = MAXDIGITS, uint8_t pos = 0);


//! Display a decimal number
//!
//! Display the given argument as a decimal number.
Expand All @@ -233,7 +232,6 @@ class TM1637TinyDisplay6 {
//! @param pos The position of the most significant digit (0 - leftmost, 5 - rightmost)
void showNumber(long num, bool leading_zero = false, uint8_t length = MAXDIGITS, uint8_t pos = 0);


//! Display a decimal number with floating point
//!
//! Display the given argument as a decimal number. Decimal point will only show up on displays
Expand Down Expand Up @@ -372,7 +370,7 @@ class TM1637TinyDisplay6 {

//! Display a sequence of raw LED segment data to create an animation
//!
//! Play thorugh an array of raw LED segment data to create a moving pattern.
//! Play through an array of raw LED segment data to create a moving pattern.
//!
//! const uint8_t Example[2][6] =
//! {
Expand Down Expand Up @@ -401,23 +399,22 @@ class TM1637TinyDisplay6 {

//! Display a sequence of raw LED segment data to create an animation (PROGMEM)
//!
//! Play thorugh an array of raw LED segment data to create a moving pattern.
//! Play through an array of raw LED segment data to create a moving pattern.
//! This function is for reading PROGMEM read-only flash memory space instead of RAM
//!
//! @param data A multi-dimensional array containing the LED segment - data[frames][4]
//! @param frames Number of frames in the sequence to animate
//! @param ms Time to delay between each frame
void showAnimation_P(const uint8_t data[][6], unsigned int frames = 0, unsigned int ms = 10);


//! The event loop function to enable non-blocking animations
//!
//! The method does not take any input parameters and returns a boolean
//! The return value is TRUE when an animation is still occuring, it is
//! FALSE when there is no animiation occuring
//! The method returns TRUE when an animation is still occurring, it is
//! FALSE when there is no animation occurring
//!
//! @return A boolean value indicating if an animation is occuring
bool Animate();
//! @return A boolean value indicating if an animation is occurring
//! @param loop If true, keep looping animation when it ends
bool Animate(bool loop = false);

//! The function used to begin a non-blocking animation
//!
Expand All @@ -427,15 +424,17 @@ class TM1637TinyDisplay6 {
void startAnimation(const uint8_t (*data)[MAXDIGITS], unsigned int frames = 0, unsigned int ms = 10, bool usePROGMEM = false);
void startAnimation_P(const uint8_t(*data)[MAXDIGITS], unsigned int frames = 0, unsigned int ms = 10);

//! The function used to stop a non-blocking animation
//!
void stopAnimation();

//! The function used to begin a non-blocking scroll of a string
//!
//! @param usePROGMEN Indicates if the passed string data is coming from a PROGMEM defined variable
//! @param ms Time to delay between each frame
void startStringScroll(const char s[], unsigned int ms = DEFAULT_SCROLL_DELAY, bool usePROGMEM = false);
void startStringScroll_P(const char s[], unsigned int ms = DEFAULT_SCROLL_DELAY);



//! Translate a single ASCII character into 7 segment code
//!
//! The method accepts a number between 0 - 255 and converts it to the
Expand All @@ -447,7 +446,6 @@ class TM1637TinyDisplay6 {
//! bit 6 - segment G; bit 7 - always zero)
uint8_t encodeASCII(uint8_t chr);


protected:
void bitDelay();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <TM1637TinyDisplay6.h>

// Module connection pins (Digital Pins)
#define CLK 8
#define DIO 9
#define CLK 4
#define DIO 5

// The amount of time (in milliseconds) between tests
#define TEST_DELAY 1000
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ startAnimation KEYWORD2
startAnimation_P KEYWORD2
startStringScroll KEYWORD2
startStringScroll_P KEYWORD2
stopAnimation KEYWORD2

#######################################
# Constants (LITERAL1)
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.9.1
version=1.10.0
author=Jason Cox <[email protected]>
maintainer=Jason Cox <[email protected]>
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 a7faa90

Please sign in to comment.