Skip to content

Commit cfe9e31

Browse files
committed
Cleaned up 7-segment clock
1 parent ae734e1 commit cfe9e31

File tree

1 file changed

+16
-66
lines changed

1 file changed

+16
-66
lines changed

sevensegwordclock/sevensegwordclock.ino

+16-66
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void setup() {
3333

3434
Serial.println("Hello 7seg Clock serial");
3535
delay(2000);
36-
display.showText("Connecting");
36+
display.showTextScroll("Connecting");
3737

3838
WiFi.begin(ssid, pass); // send credentials
3939
Serial.println("Connecting");
@@ -61,11 +61,11 @@ void loop() {
6161
// convert the system (UNIX) time to a local date and time in a configurable format
6262
struct tm *now = localtime(&present_timestamp); // break down the timestamp
6363

64-
populateTimeString(now);
64+
populateTimeStringAsNumbers(now);
6565
display.showTextScroll(dateTimeString);
6666
delay(3000);
67-
populateTimeString2(now);
68-
for (int j = 0; j < 3; ++j) {
67+
populateTimeStringAsWords(now);
68+
for (int j = 0; j < 2; ++j) {
6969
display.showTextScroll(dateTimeString);
7070
}
7171
}
@@ -89,7 +89,7 @@ void time_is_set() {
8989

9090
#define countof(a) (sizeof(a) / sizeof(a[0]))
9191

92-
void populateTimeString(struct tm * dt) {
92+
void populateTimeStringAsNumbers(struct tm * dt) {
9393
int hour = dt->tm_hour;
9494
boolean ampm = hour >= 12;
9595
if (hour > 12) {
@@ -106,7 +106,7 @@ void populateTimeString(struct tm * dt) {
106106
);
107107
}
108108

109-
void populateTimeString2(struct tm * dt) {
109+
void populateTimeStringAsWords(struct tm * dt) {
110110
int hour = dt->tm_hour;
111111
boolean ampm = hour >= 12;
112112
if (hour > 12) {
@@ -148,19 +148,12 @@ void populateTimeString2(struct tm * dt) {
148148
numSpace++;
149149
len += 2;
150150
}
151-
// Serial.print("oldlen: "); Serial.println(strlen(temp));
152-
// Serial.print("newlen: "); Serial.println(len);
153-
// Serial.print("numspace: "); Serial.println(numSpace);
154151
// Clear the final destination; copy the temporary string into the right
155152
// spot, then fix the end-of-string marker.
156153
memset(dateTimeString, ' ', BUFFER_SIZE);
157154
strcpy(&dateTimeString[numSpace], temp);
158155
dateTimeString[numSpace + strlen(temp)] = ' ';
159156
dateTimeString[len] = 0;
160-
//Serial.print("old string: "); Serial.println(temp);
161-
//Serial.print("new string: ."); Serial.print(dateTimeString); Serial.println(".");
162-
// . Twenty to Four .
163-
// . Quarter to Four .
164157
}
165158

166159
const char *getHour(int hour) {
@@ -184,61 +177,18 @@ const char *getHour(int hour) {
184177

185178
const char *getMinute(int minute) {
186179
switch (minute) {
187-
case 58: case 59: case 0: case 1: case 2: case 3: return "O'clock";
188-
case 4: case 5: case 6: case 7: return "Five Past";
189-
case 8: case 9: case 10: case 11: case 12: case 13: return "Ten Past";
190-
case 14: case 15: case 16: return "Quarter Past";
191-
case 17: case 18: case 19: case 20: case 21: case 22: case 23: return "Twenty Past";
192-
case 24: case 25: case 26: case 27: return "Twenty five Past";
180+
case 58: case 59: case 0: case 1: case 2: return "O'clocK";
181+
case 3: case 4: case 5: case 6: case 7: return "Five Past";
182+
case 8: case 9: case 10: case 11: case 12: return "Ten Past";
183+
case 13: case 14: case 15: case 16: case 17: return "Quarter Past";
184+
case 18: case 19: case 20: case 21: case 22: return "20 Past";
185+
case 23: case 24: case 25: case 26: case 27: return "25 Past";
193186
case 28: case 29: case 30: case 31: case 32: return "Half Past";
194-
case 33: case 34: case 35: case 36: return "Twenty five to";
195-
case 37: case 38: case 39: case 40: case 41: case 42: case 43: return "20 to";
196-
case 44: case 45: case 46: return "Quarter to";
197-
case 47: case 48: case 49: case 50: case 51: case 52: return "Ten to";
187+
case 33: case 34: case 35: case 36: case 37: return "25 to";
188+
case 38: case 39: case 40: case 41: case 42: return "20 to";
189+
case 43: case 44: case 45: case 46: case 47: return "Quarter to";
190+
case 48: case 49: case 50: case 51: case 52: return "Ten to";
198191
case 53: case 54: case 55: case 56: case 57: return "Five to";
199192
default: return "";
200193
}
201194
}
202-
203-
// ....................................................................................
204-
void displayDateAndTime() {
205-
Serial.print(present_timestamp); // display system time as UNIX timestamp
206-
207-
// use ctime() to convert the system (UNIX) time to a local date and time in readable form
208-
// NOTE: 'ctime' produces a output in a specific format that looks
209-
// like --> Fri Mar 22 12:11:51 2019 -there is also a newline (\n) appended
210-
Serial.print(" ");
211-
Serial.print(ctime(&present_timestamp)); // convert timestamp and display
212-
213-
struct tm *tmp ; // NOTE: structure tm is defined in time.h
214-
char formattedTime[50]; // filled by strftime()
215-
216-
// convert the system (UNIX) time to a local date and time in a configurable format
217-
218-
tmp = localtime(&present_timestamp); // break down the timestamp
219-
220-
// use strftime() to display the date and time in some other formats
221-
// https://www.geeksforgeeks.org/strftime-function-in-c/
222-
223-
// the following gives output in this form --> 03/22/19 - 12:11 pm EDT
224-
// where %x --> writes localized date representation
225-
// %I --> writes hour as a decimal number, 12 hour clock (range [01,12])
226-
227-
// %M --> writes minute as a decimal number (range [00,59])
228-
// %P --> writes localized a.m. or p.m. (locale dependent)
229-
// %Z --> time zone abbreviation name
230-
strftime(formattedTime, sizeof(formattedTime), "%x - %I:%M%P %Z", tmp);
231-
Serial.println(formattedTime);
232-
display.showTextScroll(formattedTime);
233-
delay(5000);
234-
235-
// the following gives output in this form --> 2019-03-22 12:11:51
236-
// %F --> equivalent to "%Y-%m-%d" (the ISO 8601 date format)
237-
// %T --> equivalent to "%H:%M:%S" (the ISO 8601 time format)
238-
strftime(formattedTime, sizeof(formattedTime), "%F %T", tmp);
239-
Serial.println(formattedTime);
240-
display.showTextScroll(formattedTime);
241-
delay(5000);
242-
243-
Serial.println();
244-
}

0 commit comments

Comments
 (0)