forked from arduino/ArduinoCore-renesas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request arduino#312 from misaz/add_text_animation
Add support for scrolling text asynchronously
- Loading branch information
Showing
3 changed files
with
126 additions
and
9 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...trix/examples/TextWithArduinoGraphicsAsynchronous/TextWithArduinoGraphicsAsynchronous.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// To use ArduinoGraphics APIs, please include BEFORE Arduino_LED_Matrix and TextAnimation | ||
#include "ArduinoGraphics.h" | ||
#include "Arduino_LED_Matrix.h" | ||
#include "TextAnimation.h" | ||
|
||
ArduinoLEDMatrix matrix; | ||
|
||
// 100 frames maximum. Compute as maximum length of text you want to print (eg. 20 chars) | ||
// multiplied by font width (eg. 5 for Font_5x7), so 20 chars * 5 px = 100. If you enter lower | ||
// value (or your text get unexpectedly long), animation will be cut and end soon. | ||
TEXT_ANIMATION_DEFINE(anim, 100) | ||
|
||
int counter; | ||
bool requestNext = false; | ||
|
||
void setup() { | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
|
||
matrix.begin(); | ||
matrix.beginDraw(); | ||
|
||
matrix.stroke(0xFFFFFFFF); | ||
matrix.textFont(Font_5x7); | ||
matrix.textScrollSpeed(60); | ||
matrix.setCallback(matrixCallback); | ||
|
||
const char text[] = " UNO r4 "; | ||
matrix.beginText(0, 1, 0xFFFFFF); | ||
matrix.println(text); | ||
matrix.endTextAnimation(SCROLL_LEFT, anim); | ||
|
||
matrix.loadTextAnimationSequence(anim); | ||
matrix.play(); | ||
|
||
// now animation play asynchronously. Will call matrixCallback once completed. | ||
} | ||
|
||
void matrixCallback() { | ||
// callback is executed in IRQ and should run as fast as possible | ||
requestNext = true; | ||
} | ||
|
||
void loop() { | ||
if (requestNext) { | ||
requestNext = false; | ||
|
||
matrix.beginText(0, 1, 0xFFFFFF); | ||
matrix.print(" "); | ||
matrix.println(counter); | ||
matrix.endTextAnimation(SCROLL_RIGHT, anim); | ||
|
||
if (counter++ >= 20) { | ||
counter = 0; | ||
} | ||
|
||
matrix.loadTextAnimationSequence(anim); | ||
matrix.play(); | ||
} | ||
|
||
delay(500); | ||
digitalWrite(LED_BUILTIN, 0); | ||
delay(500); | ||
digitalWrite(LED_BUILTIN, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include "Arduino.h" | ||
|
||
#if not __has_include("ArduinoGraphics.h") | ||
#error "TextAnimation work only when ArduinoGraphics is installed and used. Include ArduinoGraphics first." | ||
#endif | ||
|
||
#define TEXT_ANIMATION_DECLARE(NAME, MAX_CHARS) \ | ||
extern uint32_t NAME ## _buf[MAX_CHARS][4]; \ | ||
extern uint32_t NAME ## _buf_used; | ||
|
||
#define TEXT_ANIMATION_DEFINE(NAME, MAX_CHARS) \ | ||
uint32_t NAME ## _buf[MAX_CHARS][4]; \ | ||
uint32_t NAME ## _buf_used = 0; |