forked from arduino/ArduinoCore-renesas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextWithArduinoGraphicsAsynchronous.ino
64 lines (49 loc) · 1.56 KB
/
TextWithArduinoGraphicsAsynchronous.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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);
}