forked from pkourany/RGB_Matrix_Panel_FAST
-
Notifications
You must be signed in to change notification settings - Fork 2
/
KingdomGUI.ino
223 lines (174 loc) · 4.98 KB
/
KingdomGUI.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include "application.h"
#include "Adafruit_mfGFX.h" // Core graphics library
#include "RGBmatrixPanel.h" // Hardware-specific library
#include "math.h"
//SYSTEM_MODE(SEMI_AUTOMATIC);
//#include "spark_disable_wlan.h"
//#include "spark_disable_cloud.h"
#if defined(SPARK)
/* is in header
#define CLK D6
#define OE D7
#define LAT A4
#define A A0
#define B A1
#define C A2
#define D A3
*/
#else
#define CLK 8 // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE 9
#define A A0
#define B A1
#define C A2
#endif
// Last parameter = 'true' enables double-buffering, for flicker-free,
// buttery smooth animation. Note that NOTHING WILL SHOW ON THE DISPLAY
// until the first call to swapBuffers(). This is normal.
//RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
// 32x32
//RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, true);
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false);
//about one 3 letter word per second
#define SECONDS_PER_CHARACTER ((1.0/5.0) * 1000.0)
#define CHAR_HEIGHT 8
#define CHAR_WIDTH 6
#define MILLISECONDS_BETWEEN_MESSAGES 0 // 5000
String message;
int xpos = 0;
int textMin;
uint8_t fontSize = 1;
uint16_t fontColor = 0x00FF;
uint16_t backColor = 0x0000;
int setText(String text);
int setFontSize(String size);
int setColor(String col);
void setup()
{
Spark.function("setText", setText);
Spark.function("setFontSize", setFontSize);
Spark.function("setColor", setColor);
Time.zone(+1); // Timezone UTC +1h
while (NULL == message || !message.length())
Spark.process();
// Spark.disconnect();
matrix.begin();
matrix.fillScreen(backColor);
matrix.setTextWrap(false);
matrix.swapBuffers(false);
matrix.setFont(COMICS_8);
textMin = 1 + message.length() * CHAR_WIDTH * fontSize * -1;
// resetMessage();
// WiFi.on();
// Spark.connect();
}
uint8_t resubscribe = 1;
uint8_t bkcol = 0;
void loop()
{
matrix.fillScreen(backColor);
matrix.setTextColor(matrix.Color333(3,3,3));
matrix.setTextSize(fontSize);
matrix.setCursor(0, -1);
if (Time.hour() < 10)
matrix.print("0");
matrix.print(Time.hour());
matrix.print(":");
if (Time.minute() < 10)
matrix.print("0");
matrix.print(Time.minute());
matrix.print(":");
if (Time.second() < 10)
matrix.print("0");
matrix.print(Time.second());
//if (Time.second() > 50)
//{
// matrix.setTextColor(matrix.Color333(3,0,0));
// matrix.setCursor((matrix.width() - CHAR_WIDTH * fontSize) / 2, matrix.height() - CHAR_HEIGHT * fontSize - 1);
//}
//else
//{
// matrix.setTextColor(matrix.Color333(0,3,0));
// matrix.setCursor(matrix.width() / 2 - CHAR_WIDTH * fontSize, matrix.height() - CHAR_HEIGHT * fontSize - 1);
//}
//matrix.print(String(59 - Time.second()));
matrix.fillRect(Time.second()+1, matrix.height()-6, matrix.width()-1, 5,
Time.second() > 50 ? matrix.Color444(10,0,0) : matrix.Color444(0,2,0));
matrix.drawRect(0, matrix.height()-7, matrix.width(), 7,
Time.second() > 50 ? matrix.Color444(10,0,0) : matrix.Color444(2,2,0));
matrix.setTextColor(fontColor);
matrix.setTextSize(fontSize*2);
matrix.setCursor(xpos, matrix.height()/2 - CHAR_HEIGHT * fontSize - 1);
if ((--xpos) <= 2*textMin)
xpos = matrix.width();
matrix.print(message);
delay(SECONDS_PER_CHARACTER / (CHAR_WIDTH * fontSize));
//updateMarqueeText();
}
int setText(String text)
{
if (NULL == text)
delay(10000); // give us 10sec
message = text.c_str();
return text.length();
}
int setFontSize(String size)
{
int fs = size.toInt();
if (0 < fs && fs < 5)
{
fontSize = fs;
}
else
fs = -1;
return fs;
}
int setColor(String col)
{
if (col.length())
if (col.startsWith("-"))
backColor = (uint16_t)(-1 * col.toInt());
else
fontColor = (uint16_t)col.toInt();
else
return ++backColor;
return col.toInt();
}
//
// Update our message params, coordinates, sizes, etc.
//
void resetMessage() {
/*
// RGB.control(false);
// Spark.connect();
xpos = matrix.width();
//figure out how many pixels long it is
textMin = 1 + message.length() * CHAR_WIDTH * fontSize * -1;
// size 1 == 8 pixels high
// size 2 == ?
matrix.setTextSize(fontSize);
matrix.setTextColor(fontColor, 0);
delay(MILLISECONDS_BETWEEN_MESSAGES);
// Spark.disconnect();
// RGB.control(true);
// RGB.color((fontColor & 0x0F00) >> 8, (fontColor & 0x00F0) >> 4, (fontColor & 0x000F));
*/
}
void updateMarqueeText() {
/*
matrix.fillScreen(0);
matrix.setRotation(0);
matrix.setCursor(xpos, 0); // start at top left, with one pixel of spacing
matrix.print(message);
matrix.setRotation(2);
//matrix.setCursor(matrix.width() - xpos + textMin, matrix.height() - CHAR_HEIGHT * fontSize);
matrix.setCursor(xpos, 0); // start at top left, with one pixel of spacing
matrix.print(message);
// Update display
//matrix.swapBuffers(false);
delay(SECONDS_PER_CHARACTER / (CHAR_WIDTH * fontSize));
if ((--xpos) <= textMin)
resetMessage();
*/
}