Skip to content

Commit e3efb20

Browse files
committed
Updated flip disc clock
Changed from turning on one disc in the bottom row every 10 seconds, to actually flipping a disc in a corner every 10 seconds. Reduced startup time
1 parent 454ebe3 commit e3efb20

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

4x7seg-flip-disc-clock/4x7seg-flip-disc-clock.ino

+37-17
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,23 @@
2626
because the SPI.h library handles the SPI hardware pins. */
2727

2828
// Use "NodeMCU 0.9 (ESP-12) to program (NOT Generic8266)
29-
#include <ESP8266WiFi.h>
29+
#include <coredecls.h> // for settimeofday_cb()
3030
#include <time.h>
31-
#include <coredecls.h> // required for settimeofday_cb()
31+
#include <ESP8266WiFi.h>
3232
#include <FlipDisc.h> // https://github.com/marcinsaj/FlipDisc
3333

34+
// Local include for sekrits
3435
#include "config.h"
3536
const char* ssid = SECRET_SSID;
3637
const char* pass = SECRET_PWD;
3738

38-
// Pin definitions for the 7-segment clock
39+
// Pin definitions for the flip clock
3940
#define EN_PIN D1
4041
#define CH_PIN D2
4142
#define PL_PIN D3
4243

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.
4446

4547
void setup() {
4648
Serial.begin(115200);
@@ -72,27 +74,28 @@ void setup() {
7274
anywhere in the code. Recommended delay range: 0 - 100ms, max 255ms */
7375
Flip.Delay(10);
7476

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();
7779
delay(500);
80+
Flip.Clear();
81+
7882
digitalWrite(LED_BUILTIN, HIGH); // turn the LED off (yes the logic is flopped)
7983

8084
// send credentials
81-
WiFi.begin(ssid, pass);
82-
8385
Serial.println("Connecting");
8486
Flip.Matrix_7Seg(C, O, N, N);
87+
WiFi.begin(ssid, pass);
8588
int dot = 0;
86-
// wait for connection
89+
// Wait for connection
8790
while (WiFi.status() != WL_CONNECTED) {
8891
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
9093
dot++;
9194
Serial.print(".");
9295
}
9396
Serial.println("Connected");
9497
Flip.Matrix_7Seg(G, O, O, D);
95-
delay(1000);
98+
delay(2000);
9699

97100
// implement NTP update of timekeeping (with automatic hourly updates)
98101
configTime(0, 0, "0.pool.ntp.org");
@@ -116,7 +119,7 @@ int last_hour;
116119
int last_min;
117120
int last_sec;
118121

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
120123
void timeUpdated() {
121124
time_t last = time(nullptr); // get UNIX timestamp
122125
struct tm *last_tm = localtime(&last); // convert to local time and break down
@@ -125,9 +128,8 @@ void timeUpdated() {
125128
char UPDATE_TIME[50]; // buffer for use by strftime()
126129
strftime(UPDATE_TIME, sizeof(UPDATE_TIME), "%T", last_tm); // extract just the 'time' portion
127130

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);
131133
}
132134

133135
// Show the time; update the globals with the "last time shown"
@@ -179,10 +181,28 @@ void loop() {
179181
14 13 12 11 10 */
180182
int sec = now->tm_sec;
181183
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
183187
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+
}
185201
}
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+
// }
186206
if ((sec % 2) == 0) {
187207
digitalWrite(LED_BUILTIN, HIGH);
188208
} else {

0 commit comments

Comments
 (0)