-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclock_disp.py
More file actions
76 lines (66 loc) · 1.82 KB
/
clock_disp.py
File metadata and controls
76 lines (66 loc) · 1.82 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
import clock
import machine
import p9813
import time
import urequests
import ujson
import utime
import gc
#import webrepl
#webrepl.start()
gc.collect()
from secrets import networks
num_conts = 8
pin_clk = machine.Pin(5, machine.Pin.OUT) #D1
pin_data = machine.Pin(4, machine.Pin.OUT) #D2
chain = p9813.P9813(pin_clk, pin_data, num_conts)
#connect to wifi
import network, time
ap = network.WLAN(network.AP_IF)
ap.active(False)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
nets = wlan.scan()
for net in nets:
ssid = net[0].decode()
if ssid in networks:
print("Network found ", ssid)
wlan.connect(ssid, networks[ssid])
while not wlan.isconnected():
time.sleep(1)
print("Connected to ", ssid)
ip = wlan.ifconfig()[0]
print("IP:", ip)
break
else:
print(net[0].decode(), " not in known networks")
else:
print("No known networks seen. Switching off networking")
wlan.active(False)
def set_time():
resp = urequests.get("http://idea.bodaegl.com/time.json")
t = ujson.loads(resp.text)
clock.clockSet(t['hours'], t['minutes'], t['seconds'])
print("Time set to ", t['hours'], ":", t['minutes'], ":", t['seconds'])
def run():
sep = True
cnt = 0
while True:
cnt += 1
if cnt > 3600:
set_time()
cnt = 0
_,_,_,_,h,m,s,ms = machine.RTC().datetime()
if (h > 12):
h = h - 12
c = clock.generateClock(h, m, sep)
print('{:02}{}{:02} = '.format(h, ':' if sep else ' ',m), c)
print("Free: ", gc.mem_free(), " Allocated: ", gc.mem_alloc())
for i in range(num_conts):
chain[i] = c[i]
chain.write()
sep = not sep
_,_,_,_,h,m,s,ms = machine.RTC().datetime()
utime.sleep_ms(1000 - ms)
set_time()
run()