@@ -33,7 +33,7 @@ void setup() {
33
33
34
34
Serial.println (" Hello 7seg Clock serial" );
35
35
delay (2000 );
36
- display.showText (" Connecting" );
36
+ display.showTextScroll (" Connecting" );
37
37
38
38
WiFi.begin (ssid, pass); // send credentials
39
39
Serial.println (" Connecting" );
@@ -61,11 +61,11 @@ void loop() {
61
61
// convert the system (UNIX) time to a local date and time in a configurable format
62
62
struct tm *now = localtime (&present_timestamp); // break down the timestamp
63
63
64
- populateTimeString (now);
64
+ populateTimeStringAsNumbers (now);
65
65
display.showTextScroll (dateTimeString);
66
66
delay (3000 );
67
- populateTimeString2 (now);
68
- for (int j = 0 ; j < 3 ; ++j) {
67
+ populateTimeStringAsWords (now);
68
+ for (int j = 0 ; j < 2 ; ++j) {
69
69
display.showTextScroll (dateTimeString);
70
70
}
71
71
}
@@ -89,7 +89,7 @@ void time_is_set() {
89
89
90
90
#define countof (a ) (sizeof (a) / sizeof (a[0 ]))
91
91
92
- void populateTimeString (struct tm * dt) {
92
+ void populateTimeStringAsNumbers (struct tm * dt) {
93
93
int hour = dt->tm_hour ;
94
94
boolean ampm = hour >= 12 ;
95
95
if (hour > 12 ) {
@@ -106,7 +106,7 @@ void populateTimeString(struct tm * dt) {
106
106
);
107
107
}
108
108
109
- void populateTimeString2 (struct tm * dt) {
109
+ void populateTimeStringAsWords (struct tm * dt) {
110
110
int hour = dt->tm_hour ;
111
111
boolean ampm = hour >= 12 ;
112
112
if (hour > 12 ) {
@@ -148,19 +148,12 @@ void populateTimeString2(struct tm * dt) {
148
148
numSpace++;
149
149
len += 2 ;
150
150
}
151
- // Serial.print("oldlen: "); Serial.println(strlen(temp));
152
- // Serial.print("newlen: "); Serial.println(len);
153
- // Serial.print("numspace: "); Serial.println(numSpace);
154
151
// Clear the final destination; copy the temporary string into the right
155
152
// spot, then fix the end-of-string marker.
156
153
memset (dateTimeString, ' ' , BUFFER_SIZE);
157
154
strcpy (&dateTimeString[numSpace], temp);
158
155
dateTimeString[numSpace + strlen (temp)] = ' ' ;
159
156
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 .
164
157
}
165
158
166
159
const char *getHour (int hour) {
@@ -184,61 +177,18 @@ const char *getHour(int hour) {
184
177
185
178
const char *getMinute (int minute) {
186
179
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" ;
193
186
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" ;
198
191
case 53 : case 54 : case 55 : case 56 : case 57 : return " Five to" ;
199
192
default : return " " ;
200
193
}
201
194
}
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