-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesp_clock.py
63 lines (50 loc) · 1.58 KB
/
esp_clock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import board
import network
import time
import ntptime
import bitbangio as io
import adafruit_ht16k33.segments
ssid = ''
password = ''
i2c = io.I2C(board.SCL, board.SDA)
display = adafruit_ht16k33.segments.Seg14x4(i2c)
display.fill(0)
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
sta_if.active(True)
sta_if.connect(ssid, password)
while not sta_if.isconnected():
pass
#TZ = 14400 # UTC to EDT
TZ = 18000 # UTC to EST
t = None
while not t:
time.sleep(0.1)
try:
t = ntptime.ntptime()
except Exception:
pass
mono_time = int(time.monotonic())
while True:
tm = t - mono_time + int(time.monotonic())
now = time.localtime(tm-TZ)
hr = now.tm_hour % 12 # 12-hour time for humans
zero = 0
if hr == 0:
hr = 12 # also for humans
# to-do, check NTP again and reset ms offsets to keep the planes in the air without a reboot
# if (tm-TZ)%43200 < 6: # possibly obo, but not on the skip side, to reset the display to not show the 1 in the tens column when the clock goes from 12 to 1
# display.fill(0)
if int(hr/10) == 0 and zero == 0:
display.fill(0)
zero += 1
elif int(hr/10) == 0:
pass
else:
display[0] = '1' # give me a break, its 12-hour time
zero = 0
display[1] = str(int(hr % 10))
display[2] = str(int(now.tm_min/10))
display[3] = str(int(now.tm_min % 10))
display.show()
time.sleep(10) # this is the counter of "how far behind can we wait to flip the minute"? 5 seconds, impacts our tens of hours reset