Skip to content

Commit 258ed73

Browse files
committed
Fixed bug in the library whereby if you try to scroll something smaller than the display, it crashes. Also fixed the am/pm problem.
1 parent 3003d33 commit 258ed73

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

wordclock/LEDDisplayDriver.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,14 @@ void LEDDisplayDriver::showText(const char *msg, byte first, byte count) {
428428

429429
#ifdef _INCLUDE_SCROLLING_TEXT_
430430
void LEDDisplayDriver::showTextScroll(const char *msg, byte first, byte count) {
431-
for (byte i = 0; i <= strlen(msg) - count; i++) {
431+
byte end;
432+
if (count >= strlen(msg)) {
433+
end = 0;
434+
} else {
435+
end = strlen(msg) - count;
436+
}
437+
438+
for (byte i = 0; i <= end; i++) {
432439
showText(msg + i, first, count);
433440
if (!autoUpdate) update();
434441
delay(scrollDelay);

wordclock/wordclock.ino

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void setup() {
2626
populateTimeString(compiled);
2727
Serial.println(dateTimeString);
2828

29-
display.showText("Hello Wordclock");
29+
display.showTextScroll("Hello Wordclock");
3030
delay(2000);
3131

3232
Serial.println("hello serial Wordclock");
@@ -77,7 +77,7 @@ void loop() {
7777
display.showText(dateTimeString);
7878
delay(2000);
7979
populateTimeString2(now);
80-
display.showText(dateTimeString);
80+
display.showTextScroll(dateTimeString);
8181
}
8282
delay(10000);
8383
}
@@ -87,7 +87,7 @@ void loop() {
8787

8888
void populateTimeString(const RtcDateTime& dt) {
8989
int hour = dt.Hour();
90-
boolean ampm = hour > 12;
90+
boolean ampm = hour >= 12;
9191
if (hour > 12) {
9292
hour -= 12;
9393
}
@@ -101,11 +101,12 @@ void populateTimeString(const RtcDateTime& dt) {
101101

102102
void populateTimeString2(const RtcDateTime& dt) {
103103
int hour = dt.Hour();
104-
boolean ampm = hour > 12;
104+
boolean ampm = hour >= 12;
105105
if (hour > 12) {
106106
hour -= 12;
107107
}
108108
int minute = dt.Minute();
109+
const char *separator = " ";
109110
const char *hourStr = getHour(hour);
110111
const char *minuteStr = getMinute(minute);
111112
if (minute >= 33) {
@@ -116,15 +117,17 @@ void populateTimeString2(const RtcDateTime& dt) {
116117
if (hour == 0 || hour == 12) {
117118
// don't show "noon o'clock"
118119
minuteStr = "";
120+
separator = "";
119121
} else {
120122
// swap; instead of "O'clock Ten" it's "Ten O'clock".
121123
const char *temp; temp = hourStr; hourStr = minuteStr; minuteStr = temp;
122124
}
123125
}
124126
snprintf_P(dateTimeString,
125127
countof(dateTimeString),
126-
PSTR("%s %s"),
128+
PSTR("%s%s%s"),
127129
minuteStr,
130+
separator,
128131
hourStr
129132
);
130133
}
@@ -154,11 +157,11 @@ const char *getMinute(int minute) {
154157
case 8: case 9: case 10: case 11: case 12: case 13: return "Ten Past";
155158
case 14: case 15: case 16: return "Quarter Past";
156159
case 17: case 18: case 19: case 20: case 21: case 22: case 23: return "Twenty Past";
157-
case 24: case 25: case 26: case 27: return "25 Past";
160+
case 24: case 25: case 26: case 27: return "Twenty five Past";
158161
case 28: case 29: case 30: case 31: case 32: return "Half Past";
159-
case 33: case 34: case 35: case 36: return "25 to";
162+
case 33: case 34: case 35: case 36: return "Twenty five to";
160163
case 37: case 38: case 39: case 40: case 41: case 42: case 43: return "Twenty to";
161-
case 44: case 45: case 46: return "Quarter to";
164+
case 44: case 45: case 46: return "A Quarter to";
162165
case 47: case 48: case 49: case 50: case 51: case 52: return "Ten to";
163166
case 53: case 54: case 55: case 56: case 57: return "Five to";
164167
}

0 commit comments

Comments
 (0)