jasonacox / TM1637TinyDisplay

Arduino library to display numbers and text on a 4 and 6 digit 7-segment TM1637 display modules.
GNU Lesser General Public License v3.0
69 stars 19 forks source link

Add non-blocking animation and string scrolling to 4-digit display #24

Closed hackerceo closed 1 year ago

hackerceo commented 1 year ago

This PR adds non-blocking animation and scrolling to the TM1637TinyDisplay library.

Setup your scrolling message using display.scrollString() function. Setup your animation using display.startAnimation() function.

Both scrollString() and startAnimations() take a boolean as a first parameter to determine if the animation sequence or string to scroll are defined as PROGMEM variables.

In your main loop you must call the display.Animate() function for it to work. The function returns TRUE while an animation is playing or a message is scrolling. The Animate() function is optimized to only run when a new frame should be displayed. The Animate() function runs using millis() function and start timestamps to determine which frame to be displayed. If some long running code gets executed between Animate() calls then it will drop the missed frames and display the frame which is at thee appropriate time for the animation.

jasonacox commented 1 year ago

Brilliant!!! I love this @hackerceo - I can't wait to add this to my projects!

One minor change suggestion for API consistency: Can we change the parameters for scrollString() and startAnimation() slightly to better align to the rest of the functions by putting the content payload first and put bool usePROGMEM = false at the end with a default to false? I would even suggest adding a scrollString_P() and startAnimation_P() that are alias functions that call their main functions with usePROGMEM = true.

Seems like that would help with consistency, but I could be convinced otherwise. What do you think?

  void startAnimation(const uint8_t (*data)[4], unsigned int frames = 0, unsigned int ms = 10, bool usePROGMEM = false );
  void scrollString(const char s[], unsigned int ms = DEFAULT_SCROLL_DELAY, bool usePROGMEM = false);
hackerceo commented 1 year ago

The previous suggestions have been added into this PR. This is now ready to be merged into your branch. I think you still need to add the new functions into the sketch used by your automatic build testing.

jasonacox commented 1 year ago

Merge completed. 🚀 I'll bundle this as v1.7.0 and add a TODO to port to 6-digit displays as well.

Thanks for this great enhancement @hackerceo !