26
26
because the SPI.h library handles the SPI hardware pins. */
27
27
28
28
// Use "NodeMCU 0.9 (ESP-12) to program (NOT Generic8266)
29
- #include < ESP8266WiFi .h>
29
+ #include < coredecls .h> // for settimeofday_cb()
30
30
#include < time.h>
31
- #include < coredecls .h> // required for settimeofday_cb()
31
+ #include < ESP8266WiFi .h>
32
32
#include < FlipDisc.h> // https://github.com/marcinsaj/FlipDisc
33
33
34
+ // Local include for sekrits
34
35
#include " config.h"
35
36
const char * ssid = SECRET_SSID;
36
37
const char * pass = SECRET_PWD;
37
38
38
- // Pin definitions for the 7-segment clock
39
+ // Pin definitions for the flip clock
39
40
#define EN_PIN D1
40
41
#define CH_PIN D2
41
42
#define PL_PIN D3
42
43
43
- // Note, MOSI (DataIn), Clk (SCK) are defaulted to D7 and D5, respectively on the 8266 I have
44
+ // Note, MOSI (DataIn), Clk (SCLK) default to D7 and D5, respectively, on the 8266 I have.
45
+ // I don't know how to change these, shrug.
44
46
45
47
void setup () {
46
48
Serial.begin (115200 );
@@ -72,27 +74,28 @@ void setup() {
72
74
anywhere in the code. Recommended delay range: 0 - 100ms, max 255ms */
73
75
Flip.Delay (10 );
74
76
75
- /* The function is used to test all declared displays - turn on and off all displays */
76
- Flip.Test ();
77
+ /* Turn on and off all displays */
78
+ Flip.All ();
77
79
delay (500 );
80
+ Flip.Clear ();
81
+
78
82
digitalWrite (LED_BUILTIN, HIGH); // turn the LED off (yes the logic is flopped)
79
83
80
84
// send credentials
81
- WiFi.begin (ssid, pass);
82
-
83
85
Serial.println (" Connecting" );
84
86
Flip.Matrix_7Seg (C, O, N, N);
87
+ WiFi.begin (ssid, pass);
85
88
int dot = 0 ;
86
- // wait for connection
89
+ // Wait for connection
87
90
while (WiFi.status () != WL_CONNECTED) {
88
91
delay (500 );
89
- Flip.Disc_7Seg (1 , dot % 23 , dot % 2 ); // last argument can be 0 to turn off
92
+ Flip.Disc_7Seg (1 , ( dot/ 2 ) % 23 , dot % 2 ); // last argument can be 0 to turn off
90
93
dot++;
91
94
Serial.print (" ." );
92
95
}
93
96
Serial.println (" Connected" );
94
97
Flip.Matrix_7Seg (G, O, O, D);
95
- delay (1000 );
98
+ delay (2000 );
96
99
97
100
// implement NTP update of timekeeping (with automatic hourly updates)
98
101
configTime (0 , 0 , " 0.pool.ntp.org" );
@@ -116,7 +119,7 @@ int last_hour;
116
119
int last_min;
117
120
int last_sec;
118
121
119
- // callback routine - arrive here whenever a successful NTP update has occurred
122
+ // Callback routine - we arrive here whenever a successful NTP update has occurred
120
123
void timeUpdated () {
121
124
time_t last = time (nullptr ); // get UNIX timestamp
122
125
struct tm *last_tm = localtime (&last); // convert to local time and break down
@@ -125,9 +128,8 @@ void timeUpdated() {
125
128
char UPDATE_TIME[50 ]; // buffer for use by strftime()
126
129
strftime (UPDATE_TIME, sizeof (UPDATE_TIME), " %T" , last_tm); // extract just the 'time' portion
127
130
128
- Serial.print (" -------- NTP update at " );
129
- Serial.print (UPDATE_TIME);
130
- Serial.println (" --------" );
131
+ Serial.print (" NTP update at " );
132
+ Serial.println (UPDATE_TIME);
131
133
}
132
134
133
135
// Show the time; update the globals with the "last time shown"
@@ -179,10 +181,28 @@ void loop() {
179
181
14 13 12 11 10 */
180
182
int sec = now->tm_sec ;
181
183
if (sec != last_sec) {
182
- // Flip one disc in bottom row to indicate 10s of seconds.
184
+ int hour = now->tm_hour ;
185
+ int hr10 = hour / 10 ;
186
+ // If hour is 10-12, turn bit 10 off, otherwise turn bit 10 on
183
187
for (int i = 0 ; i < sec / 10 ; i++) {
184
- Flip.Disc_7Seg (1 , 10 + i, 1 ); // last argument can be 0 to turn off
188
+ if (i == 0 && hr10 == 1 ) {
189
+ // Serial.println("turning *on* bit 10 of 1");
190
+ Flip.Disc_7Seg (i + 1 , 10 , 1 );
191
+ } else {
192
+ if (i > 3 ) {
193
+ // if we're in the last 10 seconds, turn off bit 4 instead.
194
+ // Serial.println("turning off bit 4 of 4");
195
+ Flip.Disc_7Seg (4 , 4 , 0 );
196
+ } else {
197
+ // Serial.print("turning off bit 10 of "); Serial.println(i + 1);
198
+ Flip.Disc_7Seg (i + 1 , 10 , 0 );
199
+ }
200
+ }
185
201
}
202
+ // Flip one disc in bottom row to indicate 10s of seconds.
203
+ // for (int i = 0; i < sec / 10; i++) {
204
+ // Flip.Disc_7Seg(1, 10 + i, 1); // last argument can be 0 to turn off
205
+ // }
186
206
if ((sec % 2 ) == 0 ) {
187
207
digitalWrite (LED_BUILTIN, HIGH);
188
208
} else {
0 commit comments