-
Notifications
You must be signed in to change notification settings - Fork 2
/
wordclockfunctions.ino
225 lines (205 loc) · 4.63 KB
/
wordclockfunctions.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
224
225
const String clockStringGerman = "ESPISTAFUNFVIERTELZEHNZWANZIGUVORTECHNICNACHHALBMELFUNFXCONTROLLEREINSEAWZWEIDREITUMVIERSECHSQYACHTSIEBENZWOLFZEHNEUNJUHR";
/**
* @brief control the four minute indicator LEDs
*
* @param minutes minutes to be displayed [0 ... 59]
* @param color 24bit color value
*/
void drawMinuteIndicator(uint8_t minutes, uint32_t color){
//separate LEDs for minutes in an additional row
{
switch (minutes%5)
{
case 0:
break;
case 1:
ledmatrix.setMinIndicator(0b1000, color);
break;
case 2:
ledmatrix.setMinIndicator(0b1100, color);
break;
case 3:
ledmatrix.setMinIndicator(0b1110, color);
break;
case 4:
ledmatrix.setMinIndicator(0b1111, color);
break;
}
}
}
/**
* @brief Draw the given sentence to the word clock
*
* @param message sentence to be displayed
* @param color 24bit color value
* @return int: 0 if successful, -1 if sentence not possible to display
*/
int showStringOnClock(String message, uint32_t color){
int messageStart = 0;
String word = "";
int lastLetterClock = 0;
int positionOfWord = 0;
int nextSpace = 0;
int index = 0;
// add space on the end of message for splitting
message = message + " ";
// empty the targetgrid
ledmatrix.gridFlush();
while(true){
// extract next word from message
word = split(message, ' ', index);
index++;
if(word.length() > 0){
// find word in clock string
positionOfWord = clockStringGerman.indexOf(word, lastLetterClock);
if(positionOfWord >= 0){
// word found on clock -> enable leds in targetgrid
for(int i = 0; i < word.length(); i++){
int x = (positionOfWord + i)%WIDTH;
int y = (positionOfWord + i)/WIDTH;
ledmatrix.gridAddPixel(x, y, color);
}
// remember end of the word on clock
lastLetterClock = positionOfWord + word.length();
}
else{
// word is not possible to show on clock
logger.logString("word is not possible to show on clock: " + String(word));
return -1;
}
//logger.logString(String(nextSpace) + " - " + String());
}else{
// end - no more word in message
break;
}
}
// return success
return 0;
}
/**
* @brief Converts the given time as sentence (String)
*
* @param hours hours of the time value
* @param minutes minutes of the time value
* @return String time as sentence
*/
String timeToString(uint8_t hours,uint8_t minutes){
Serial.println(hours);
Serial.println(minutes);
//ES IST
String message = "";
if(minutes < 5 || (minutes >= 30 && minutes < 35) || !puristMode )
{
message += "ES IST ";
}
//show minutes
if(minutes >= 5 && minutes < 10)
{
message += "FUNF NACH ";
}
else if(minutes >= 10 && minutes < 15)
{
message += "ZEHN NACH ";
}
else if(minutes >= 15 && minutes < 20)
{
message += "VIERTEL NACH ";
}
else if(minutes >= 20 && minutes < 25)
{
message += "ZWANZIG NACH ";
}
else if(minutes >= 25 && minutes < 30)
{
message += "FUNF VOR HALB ";
}
else if(minutes >= 30 && minutes < 35)
{
message += "HALB ";
}
else if(minutes >= 35 && minutes < 40)
{
message += "FUNF NACH HALB ";
}
else if(minutes >= 40 && minutes < 45)
{
message += "ZWANZIG VOR ";
}
else if(minutes >= 45 && minutes < 50)
{
message += "VIERTEL VOR ";
}
else if(minutes >= 50 && minutes < 55)
{
message += "ZEHN VOR ";
}
else if(minutes >= 55 && minutes < 60)
{
message += "FUNF VOR ";
}
//convert hours to 12h format
if(hours >= 12)
{
hours -= 12;
}
if(minutes >= 25)
{
hours++;
}
if(hours == 12)
{
hours = 0;
}
// show hours
switch(hours)
{
case 0:
message += "ZWOLF ";
break;
case 1:
message += "EIN";
//EIN(S)
if(minutes > 4){
message += "S";
}
message += " ";
break;
case 2:
message += "ZWEI ";
break;
case 3:
message += "DREI ";
break;
case 4:
message += "VIER ";
break;
case 5:
message += "FUNF ";
break;
case 6:
message += "SECHS ";
break;
case 7:
message += "SIEBEN ";
break;
case 8:
message += "ACHT ";
break;
case 9:
message += "NEUN ";
break;
case 10:
message += "ZEHN ";
break;
case 11:
message += "ELF ";
break;
}
if(minutes < 5)
{
message += "UHR ";
}
Serial.println(message);
logger.logString("time as String: " + String(message));
return message;
}