14
14
2. Or any Arduino board + Pulse Shaper Power Supply - https://bit.ly/PSPS-FD
15
15
----------------------------------------------------------------------------------*/
16
16
17
+ // Use "NodeMCU 0.9 (ESP-12)" or "WEMOS D1 (clone)" to program (NOT Generic8266)
18
+
17
19
/* The library <FlipDisc.h> uses SPI to control flip-disc displays.
18
20
The user must remember to connect the display inputs marked:
19
21
- DIN - data in - to the MOSI (SPI) output of the microcontroller,
25
27
The declaration of DIN (MOSI) and CLK (SCK) is not necessary,
26
28
because the SPI.h library handles the SPI hardware pins. */
27
29
28
- // Use "NodeMCU 0.9 (ESP-12) to program (NOT Generic8266)
29
30
#include < coredecls.h> // for settimeofday_cb()
30
31
#include < time.h>
32
+
31
33
#include < ESP8266WiFi.h>
34
+ #include < ESP8266mDNS.h>
35
+ #include < WiFiUdp.h>
36
+ #include < ArduinoOTA.h>
37
+
32
38
#include < FlipDisc.h> // https://github.com/marcinsaj/FlipDisc
33
39
34
40
// Local include for sekrits
35
41
#include " config.h"
36
42
const char * ssid = SECRET_SSID;
37
43
const char * pass = SECRET_PWD;
38
44
45
+ // For OTA upload status
46
+ int progressStatus = 0 ;
47
+
39
48
// Pin definitions for the flip clock
40
49
#define EN_PIN D1
41
50
#define CH_PIN D2
42
51
#define PL_PIN D3
43
52
44
- // Note, MOSI (DataIn), Clk (SCLK) default to D7 and D5, respectively, on the 8266 I have.
53
+ // Note, MOSI (DataIn), Clk (SCLK) default to D7 and D5, respectively, on the ESP8266 I have.
45
54
// I don't know how to change these, shrug.
46
55
47
56
void setup () {
@@ -84,12 +93,13 @@ void setup() {
84
93
// send credentials
85
94
Serial.println (" Connecting" );
86
95
Flip.Matrix_7Seg (C, O, N, N);
96
+ WiFi.mode (WIFI_STA);
87
97
WiFi.begin (ssid, pass);
88
98
int dot = 0 ;
89
99
// Wait for connection
90
- while (WiFi.status () != WL_CONNECTED) {
100
+ while (WiFi.waitForConnectResult () != WL_CONNECTED) {
91
101
delay (500 );
92
- Flip.Disc_7Seg (1 , (dot/ 2 ) % 23 , dot % 2 ); // last argument can be 0 to turn off
102
+ Flip.Disc_7Seg (1 , (dot / 2 ) % 23 , dot % 2 ); // last argument can be 0 to turn off
93
103
dot++;
94
104
Serial.print (" ." );
95
105
}
@@ -113,6 +123,55 @@ void setup() {
113
123
settimeofday_cb (timeUpdated);
114
124
115
125
digitalWrite (LED_BUILTIN, LOW);
126
+
127
+ // All sorts of OTA (over-the-air) updates.
128
+ // Code mostly copied from https://randomnerdtutorials.com/esp8266-ota-updates-with-arduino-ide-over-the-air/
129
+ ArduinoOTA.setPort (OTA_PORT);
130
+ ArduinoOTA.setHostname (" flipclock" );
131
+ ArduinoOTA.setPassword (OTA_PASSWORD);
132
+ ArduinoOTA.onStart ([]() {
133
+ progressStatus = 0 ;
134
+ Flip.Matrix_7Seg (S, T, R, T);
135
+ digitalWrite (LED_BUILTIN, LOW);
136
+ Serial.println (" Start" );
137
+ });
138
+ ArduinoOTA.onEnd ([]() {
139
+ digitalWrite (LED_BUILTIN, HIGH);
140
+ Flip.Matrix_7Seg (E, N, D, CLR);
141
+ Serial.println (" \n End" );
142
+ });
143
+ ArduinoOTA.onProgress ([](unsigned int progress, unsigned int total) {
144
+ if (progressStatus == 0 ) {
145
+ Flip.Matrix_7Seg (P, R, O, G);
146
+ }
147
+ digitalWrite (LED_BUILTIN, progressStatus % 2 );
148
+ progressStatus++;
149
+ Serial.printf (" Progress: %u%%\r " , (progress / (total / 100 )));
150
+ });
151
+ ArduinoOTA.onError ([](ota_error_t error) {
152
+ digitalWrite (LED_BUILTIN, LOW);
153
+ Flip.Matrix_7Seg (E, R, R, CLR);
154
+ delay (2000 );
155
+ Serial.printf (" Error[%u]: " , error);
156
+ if (error == OTA_AUTH_ERROR) {
157
+ Flip.Matrix_7Seg (A, U, T, H);
158
+ Serial.println (" Auth Failed" );
159
+ } else if (error == OTA_BEGIN_ERROR) {
160
+ Flip.Matrix_7Seg (B, E, G, N);
161
+ Serial.println (" Begin Failed" );
162
+ } else if (error == OTA_CONNECT_ERROR) {
163
+ Flip.Matrix_7Seg (C, O, N, N);
164
+ Serial.println (" Connect Failed" );
165
+ } else if (error == OTA_RECEIVE_ERROR) {
166
+ Flip.Matrix_7Seg (R, E, C, V);
167
+ Serial.println (" Receive Failed" );
168
+ } else if (error == OTA_END_ERROR) {
169
+ Flip.Matrix_7Seg (E, N, D, CLR);
170
+ Serial.println (" End Failed" );
171
+ }
172
+ delay (2000 );
173
+ });
174
+ ArduinoOTA.begin ();
116
175
}
117
176
118
177
int last_hour;
@@ -182,10 +241,13 @@ void loop() {
182
241
int sec = now->tm_sec ;
183
242
if (sec != last_sec) {
184
243
int hour = now->tm_hour ;
244
+ if (hour > 12 ) {
245
+ hour -= 12 ;
246
+ }
185
247
int hr10 = hour / 10 ;
186
248
// If hour is 10-12, turn bit 10 off, otherwise turn bit 10 on
187
249
for (int i = 0 ; i < sec / 10 ; i++) {
188
- if (i == 0 && hr10 == 1 ) {
250
+ if (i == 0 && hr10 == 0 ) {
189
251
// Serial.println("turning *on* bit 10 of 1");
190
252
Flip.Disc_7Seg (i + 1 , 10 , 1 );
191
253
} else {
@@ -232,4 +294,5 @@ void loop() {
232
294
// this sets last_hour, last_min and last_sec
233
295
showTime (now->tm_hour , now->tm_min , now->tm_sec );
234
296
}
297
+ ArduinoOTA.handle ();
235
298
}
0 commit comments