forked from techniccontroller/wordclock_esp8266
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordclockfunctions.ino_english
196 lines (173 loc) · 4.63 KB
/
wordclockfunctions.ino_english
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
const String clockStringEnglish = "ITPISKTENNPQUARTERHALFTWENTYUFIVEMINUTESNATOPASTMEAONEFTWONTHREELRFOUREAWFIVEOSIXZUSEVENEIGHTELEVENUNINETWELVETENAWOCLOCK";
/**
* @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 = clockStringEnglish.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);
//IT IS
String message = "IT IS ";
//show minutes
if (minutes >= 5 && minutes < 10) {
message += "FIVE MINUTES ";
} else if (minutes >= 10 && minutes < 15) {
message += "TEN MINUTES ";
} else if (minutes >= 15 && minutes < 20) {
message += "QUARTER ";
} else if (minutes >= 20 && minutes < 25) {
message += "TWENTY MINUTES ";
} else if (minutes >= 25 && minutes < 30) {
message += "TWENTY FIVE MINUTES ";
} else if (minutes >= 30 && minutes < 35) {
message += "HALF ";
} else if (minutes >= 35 && minutes < 40) {
message += "TWENTY FIVE MINUTES ";
} else if (minutes >= 40 && minutes < 45) {
message += "TWENTY MINUTES ";
} else if (minutes >= 45 && minutes < 50) {
message += "QUARTER ";
} else if (minutes >= 50 && minutes < 55) {
message += "TEN MINUTES ";
} else if (minutes >= 55 && minutes < 60) {
message += "FIVE MINUTES ";
}
// Convert hours to 12h format and adjust for "TO" phrases
if (hours >= 12) {
hours -= 12;
}
// Increment hour for "TO" phrases (minutes 35 or more)
if (minutes >= 35) {
hours = (hours + 1) % 12;
message += "TO ";
} else if (minutes >= 5) {
message += "PAST ";
}
// Handle edge case for 0 hour (12 AM/PM)
if (hours == 0) {
hours = 12;
}
// show hours
switch (hours) {
case 1:
message += "ONE ";
break;
case 2:
message += "TWO ";
break;
case 3:
message += "THREE ";
break;
case 4:
message += "FOUR ";
break;
case 5:
message += "FIVE ";
break;
case 6:
message += "SIX ";
break;
case 7:
message += "SEVEN ";
break;
case 8:
message += "EIGHT ";
break;
case 9:
message += "NINE ";
break;
case 10:
message += "TEN ";
break;
case 11:
message += "ELEVEN ";
break;
case 12:
message += "TWELVE ";
break;
}
if (minutes < 5) {
message += "OCLOCK ";
}
Serial.println(message);
logger.logString("time as String: " + String(message));
return message;
}