-
Notifications
You must be signed in to change notification settings - Fork 20
/
wordclockfunctions.ino_javanese
188 lines (163 loc) · 4.42 KB
/
wordclockfunctions.ino_javanese
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
const String clockStringJava = "JAMASETENGAHTELOROLASIJIPAPATELUENEMPITUWOLULIMOSEPULOHSONGOOSEWELASPASIKURANGPUNJULLIMOSEPRAPATKATESEPULOHIJURONGPULOHATSELAWEMENIT";
/**
* @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) {
String word = "";
int lastLetterClock = 0;
int positionOfWord = 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 = clockStringJava.indexOf(word, lastLetterClock);
if (positionOfWord >= 0) {
// word found on clock -> enable leds in targetgrid
for (unsigned 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;
}
} 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) {
String message = "JAM ";
hours = hours % 12;
if (minutes >= 30)
hours = (hours + 1) % 12;
if (hours == 0)
hours = 12;
if (minutes >= 30 && minutes < 35)
message += "SETENGAH ";
// show hours
switch (hours) {
case 1:
message += "SIJI ";
break;
case 2:
message += "LORO ";
break;
case 3:
message += "TELU ";
break;
case 4:
message += "PAPAT ";
break;
case 5:
message += "LIMO ";
break;
case 6:
message += "ENEM ";
break;
case 7:
message += "PITU ";
break;
case 8:
message += "WOLU ";
break;
case 9:
message += "SONGO ";
break;
case 10:
message += "SEPULOH ";
break;
case 11:
message += "SEWELAS ";
break;
case 12:
message += "ROLAS ";
break;
}
if (minutes >= 35) {
message += "KURANG ";
} else if (minutes >= 5 && minutes < 30) {
message += "PUNJUL ";
}
//show minutes
if (minutes >= 5 && minutes < 10) {
message += "LIMO MENIT ";
} else if (minutes >= 10 && minutes < 15) {
message += "SEPULOH MENIT ";
} else if (minutes >= 15 && minutes < 20) {
message += "SEPRAPAT MENIT";
} else if (minutes >= 20 && minutes < 25) {
message += "RONGPULOH MENIT ";
} else if (minutes >= 25 && minutes < 30) {
message += "SELAWE MENIT ";
} else if (minutes >= 30 && minutes < 35) {
// message += "SETENGAH ";
} else if (minutes >= 35 && minutes < 40) {
message += "SELAWE MENIT ";
} else if (minutes >= 40 && minutes < 45) {
message += "RONGPULOH MENIT ";
} else if (minutes >= 45 && minutes < 50) {
message += "SEPRAPAT MENIT ";
} else if (minutes >= 50 && minutes < 55) {
message += "SEPULOH MENIT ";
} else if (minutes >= 55 && minutes < 60) {
message += "LIMO MENIT ";
}
if (minutes < 5 || (minutes >= 30 && minutes < 35)) {
message += "PAS ";
}
logger.logString("time as String: " + String(message));
return message;
}