86 lines
2.5 KiB
Python
86 lines
2.5 KiB
Python
import matrixclock
|
|
import machine,neopixel
|
|
import settings
|
|
import ntptime
|
|
import network
|
|
import time
|
|
from helpers import Time2Sentence
|
|
import pickle
|
|
import random
|
|
|
|
def Test(Display,Speed=0,Type=1):
|
|
if Type == 1:
|
|
for h in range(24):
|
|
for m in range(60):
|
|
print(Time2Sentence((2021,12,4,h,m)))
|
|
Display.WriteSentence(Time2Sentence((2021,12,4,h,m)),(60,60,60))
|
|
time.sleep(Speed)
|
|
if Type == 2:
|
|
for i in range(Display.number):
|
|
Display.np[i]=(255,255,255)
|
|
Display.np.write()
|
|
time.sleep(Speed)
|
|
Display.np[i]=(0,0,0)
|
|
|
|
np=neopixel.NeoPixel(machine.Pin(14),16)
|
|
d=matrixclock.Display(14,16,16)
|
|
d.Clear()
|
|
|
|
|
|
def DisplayTime(arg):
|
|
global Color
|
|
if str(time.localtime()[1])+str(time.localtime()[2]) in SpecialDates and time.localtime()[4] == 0 and time.localtime()[5]<5:
|
|
d.ScrollLetter(*SpecialDates[str(time.localtime()[1])+str(time.localtime()[2])])
|
|
d.WriteSentence(Time2Sentence(time.localtime()),Color)
|
|
#Color=(Color[0]+16-random.getrandbits(5),Color[1]+16-random.getrandbits(5),Color[2]+16-random.getrandbits(5))
|
|
#print(Color)
|
|
|
|
|
|
def ColorByTime(time):
|
|
return(random.getrandbits(8),random.getrandbits(8),random.getrandbits(8))
|
|
|
|
def Connect(Settings,Display=d):
|
|
sta=network.WLAN(network.STA_IF)
|
|
if sta.isconnected():
|
|
for number in 'ip %s'%sta.ifconfig()[0]:
|
|
Display.WriteWord('m'+number,(100,0,0))
|
|
time.sleep(1)
|
|
d.Clear()
|
|
return True
|
|
sta.active(True)
|
|
if ('NetMask') in dir(settings) and 'DNS' in dir(settings) and 'Gateway' in dir(settings) and 'IP' in dir(settings):
|
|
print("Static configuration active")
|
|
sta.ifconfig((settings.IP,settings.NetMask,settings.Gateway,settings.DNS))
|
|
else:
|
|
print("DHCP active")
|
|
sta.connect(settings.ssid,settings.password)
|
|
timeout=0
|
|
while timeout < 30:
|
|
if sta.isconnected():
|
|
for number in 'ip %s'%sta.ifconfig()[0]:
|
|
Display.WriteWord('m'+number,(100,0,0))
|
|
time.sleep(1)
|
|
return True
|
|
else:
|
|
timeout += 1
|
|
time.sleep(1)
|
|
print("Time waiting: %s sec"%timeout)
|
|
sta.active(False)
|
|
return False
|
|
|
|
try:
|
|
SpecialDates=pickle.loads(bytearray("".join(open("SpecialDates.json").readlines())))
|
|
except:
|
|
SpecialDates={}
|
|
|
|
Connect(settings)
|
|
ntptime.settime()
|
|
|
|
Color=(50,50,50)
|
|
|
|
T=machine.Timer(-1)
|
|
T.init(period=1000,mode=machine.Timer.PERIODIC,callback=DisplayTime)
|
|
|
|
|
|
|