-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmessage_print.ino
78 lines (69 loc) · 1.92 KB
/
message_print.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
65
66
67
68
69
70
71
72
73
74
75
76
77
// standard pixel size for Adafruit_GFX is 6px per character
static const int _pixel_size = 6;
static int _x = matrix.width();
static ColorName_t _message_color;
static bool _message_finished;
static const char *_message;
static int _message_width;
/**
* Setup a message to be scrolled
*/
void message_start(const char *str, ColorName_t color)
{
// Save the message string
if (str != NULL)
{
_message = str;
_message_width = (strlen(str) * _pixel_size);
_message_color = color;
}
_message_finished = false;
_x = matrix.width();
}
/**
* Display a scrolling message
*/
void message_scroll(void)
{
if (_message_finished == true)
{
return;
}
matrix.clear(); // Clear the screen
matrix.setCursor(_x, 0); // Set the starting point of the message
matrix.setTextColor(_colors[_message_color]);
matrix.print(_message); // Store the message at the cursor position
/**
* setCursor() sets the pixel position from where to render the text
* offset is calculated based on font width, screen width, and text length
* when offset is reached, pass is complete & color is updated
**/
// int offset = _message_width - _x;
int offset = _message_width;
_x = _x - 1; // Set the x-axis one pixel to the left
// if (_x < (0 - _message_width))
if (_x < -offset)
{
// After one time through scrolling the message, set the "done" flag
_message_finished = true;
}
matrix.show(); // Display the message as saved
}
/**
* Indicate that a message has scrolled off the screen
*/
bool message_done(void)
{
return _message_finished;
}
/**
* Print a static message on the display (not scrolled)
*/
void message_print(const char *str, ColorName_t color)
{
matrix.clear();
matrix.setCursor(0, 0);
matrix.setTextColor(_colors[color]);
matrix.print(str);
matrix.show();
}