2016-05-04 23:23:49 +02:00
|
|
|
dofile("wlancfg.lua")
|
2016-05-16 13:54:42 +02:00
|
|
|
dofile("timecore.lua")
|
2016-05-18 22:50:56 +02:00
|
|
|
dofile("wordclock.lua")
|
2016-05-16 13:54:42 +02:00
|
|
|
|
|
|
|
timezoneoffset=1
|
2016-05-04 23:23:49 +02:00
|
|
|
|
|
|
|
-- Wait to be connect to the WiFi access point.
|
|
|
|
tmr.alarm(0, 100, 1, function()
|
|
|
|
if wifi.sta.status() ~= 5 then
|
|
|
|
print("Connecting to AP...")
|
|
|
|
else
|
|
|
|
tmr.stop(0)
|
|
|
|
print('IP: ',wifi.sta.getip())
|
|
|
|
|
|
|
|
--ptbtime1.ptb.de
|
2016-05-16 13:54:42 +02:00
|
|
|
sntp.sync('ptbtime1.ptb.de',
|
2016-05-04 23:23:49 +02:00
|
|
|
function(sec,usec,server)
|
|
|
|
print('sync', sec, usec, server)
|
|
|
|
end,
|
|
|
|
function()
|
|
|
|
print('failed!')
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2016-05-22 15:31:43 +02:00
|
|
|
function generateLEDs(words)
|
2016-06-07 23:30:13 +02:00
|
|
|
|
|
|
|
color=string.char(0,0,50)
|
|
|
|
white=string.char(0,0,0)
|
|
|
|
buf=color
|
|
|
|
-- line 1----------------------------------------------
|
|
|
|
if (words.itis == 1) then
|
|
|
|
buf=color:rep(2) -- ES
|
|
|
|
-- K fill character
|
|
|
|
buf=buf .. white:rep(1)
|
|
|
|
buf=buf ..color:rep(3) -- IST
|
|
|
|
-- L fill character
|
|
|
|
buf=buf .. white:rep(1)
|
|
|
|
else
|
|
|
|
buf=white:rep(7)
|
|
|
|
end
|
|
|
|
if (words.fiveMin== 1) then
|
|
|
|
buf= buf .. color:rep(4) -- FUENF
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(4)
|
|
|
|
end
|
|
|
|
-- line 2-- even row (so inverted) --------------------
|
|
|
|
if (words.twenty == 1) then
|
|
|
|
buf= buf .. color:rep(7) -- ZWANZIG
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(7)
|
|
|
|
end
|
|
|
|
if (words.tenMin == 1) then
|
|
|
|
buf= buf .. color:rep(4) -- ZEHN
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(4)
|
|
|
|
end
|
|
|
|
-- line3----------------------------------------------
|
|
|
|
--TODO ggf. auch ueber viertel vor abbildbar
|
|
|
|
if (words.threequater == 1) then
|
|
|
|
buf= buf .. color:rep(11) -- Dreiviertel
|
|
|
|
elseif (words.quater == 1) then
|
|
|
|
buf= buf .. white:rep(4)
|
|
|
|
buf= buf .. color:rep(7) -- VIERTEL
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(11)
|
|
|
|
end
|
|
|
|
--line 4-------- even row (so inverted) -------------
|
|
|
|
if (words.before == 1) then
|
|
|
|
buf=buf .. white:rep(2)
|
|
|
|
buf= buf .. color:rep(3) -- VOR
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(5)
|
|
|
|
end
|
|
|
|
if (words.after == 1) then
|
|
|
|
buf= buf .. color:rep(4) -- NACH
|
|
|
|
buf= buf .. white:rep(2) -- TG
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(6)
|
|
|
|
end
|
|
|
|
------------------------------------------------
|
|
|
|
if (words.half == 1) then
|
|
|
|
buf= buf .. color:rep(4) -- HALB
|
|
|
|
buf= buf .. white:rep(1) -- X
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(5)
|
|
|
|
end
|
|
|
|
if (words.twelve == 1) then
|
|
|
|
buf= buf .. color:rep(5) -- ZWOELF
|
|
|
|
buf= buf .. white:rep(1) -- P
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(6)
|
|
|
|
end
|
|
|
|
------------even row (so inverted) ---------------------
|
|
|
|
if (words.seven == 1) then
|
|
|
|
buf= buf .. color:rep(6) -- SIEBEN
|
|
|
|
buf= buf .. white:rep(5)
|
|
|
|
elseif (words.one == 1) then
|
|
|
|
buf= buf .. white:rep(5)
|
|
|
|
buf= buf .. color:rep(4) -- EINS
|
|
|
|
buf= buf .. white:rep(2)
|
|
|
|
elseif (words.two == 1) then
|
|
|
|
buf= buf .. white:rep(7)
|
|
|
|
buf= buf .. color:rep(4) -- ZWEI
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(11)
|
|
|
|
end
|
|
|
|
------------------------------------------------
|
|
|
|
if (words.three == 1) then
|
|
|
|
buf= buf .. white:rep(1)
|
|
|
|
buf= buf .. color:rep(4) -- DREI
|
|
|
|
buf= buf .. white:rep(6)
|
|
|
|
elseif (words.five == 1) then
|
|
|
|
buf= buf .. white:rep(7)
|
|
|
|
buf= buf .. color:rep(4) -- FUENF
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(11)
|
|
|
|
end
|
|
|
|
------------even row (so inverted) ---------------------
|
|
|
|
if (words.four == 1) then
|
|
|
|
buf= buf .. color:rep(4) -- VIER
|
|
|
|
buf= buf .. white:rep(7)
|
|
|
|
elseif (words.nine == 1) then
|
|
|
|
buf= buf .. white:rep(4)
|
|
|
|
buf= buf .. color:rep(4) -- NEUN
|
|
|
|
buf= buf .. white:rep(3)
|
|
|
|
elseif (words.eleven == 1) then
|
|
|
|
buf= buf .. white:rep(8)
|
|
|
|
buf= buf .. color:rep(3) -- ELEVEN
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(11)
|
|
|
|
end
|
|
|
|
------------------------------------------------
|
|
|
|
if (words.eight == 1) then
|
|
|
|
buf= buf .. white:rep(1)
|
|
|
|
buf= buf .. color:rep(4) -- ACHT
|
|
|
|
buf= buf .. white:rep(6)
|
|
|
|
elseif (words.ten == 1) then
|
|
|
|
buf= buf .. white:rep(5)
|
|
|
|
buf= buf .. color:rep(4) -- ZEHN
|
|
|
|
buf= buf .. white:rep(2)
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(11)
|
|
|
|
end
|
|
|
|
------------even row (so inverted) ---------------------
|
|
|
|
if (words.clock == 1) then
|
|
|
|
buf= buf .. color:rep(3) -- UHR
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(3)
|
|
|
|
end
|
|
|
|
if (words.sechs == 1) then
|
|
|
|
buf= buf .. white:rep(2)
|
|
|
|
buf= buf .. color:rep(5) -- SECHS
|
|
|
|
buf= buf .. white:rep(1)
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(8)
|
|
|
|
end
|
|
|
|
|
|
|
|
if (words.min1 == 1) then
|
|
|
|
buf= buf .. color:rep(1)
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(1)
|
|
|
|
end
|
|
|
|
if (words.min2 == 1) then
|
|
|
|
buf= buf .. color:rep(1)
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(1)
|
|
|
|
end
|
|
|
|
if (words.min3 == 1) then
|
|
|
|
buf= buf .. color:rep(1)
|
|
|
|
else
|
|
|
|
buf= buf .. white:rep(1)
|
|
|
|
end
|
2016-05-22 15:31:43 +02:00
|
|
|
if (words.min4 == 1) then
|
2016-06-07 23:30:13 +02:00
|
|
|
buf= buf .. color:rep(1)
|
2016-05-22 15:31:43 +02:00
|
|
|
else
|
2016-06-07 23:30:13 +02:00
|
|
|
buf= buf .. white:rep(1)
|
2016-05-22 15:31:43 +02:00
|
|
|
end
|
|
|
|
return buf
|
|
|
|
end
|
2016-05-04 23:23:49 +02:00
|
|
|
|
2016-06-07 23:30:13 +02:00
|
|
|
tmr.alarm(1, 5000, 1 ,function()
|
2016-05-04 23:23:49 +02:00
|
|
|
sec, usec = rtctime.get()
|
2016-05-16 13:54:42 +02:00
|
|
|
time = getTime(sec, timezoneoffset)
|
2016-05-04 23:23:49 +02:00
|
|
|
print("Time : " , sec)
|
2016-05-16 13:54:42 +02:00
|
|
|
print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second)
|
2016-05-18 22:50:56 +02:00
|
|
|
|
|
|
|
words = display_timestat(time.hour, time.minute)
|
2016-05-22 15:31:43 +02:00
|
|
|
ledBuf = generateLEDs(words)
|
|
|
|
-- Write the buffer to the LEDs
|
|
|
|
ws2812.write(4, ledBuf)
|
2016-05-18 23:06:19 +02:00
|
|
|
|
2016-05-18 22:50:56 +02:00
|
|
|
for key,value in pairs(words) do
|
|
|
|
if (value > 0) then
|
|
|
|
print(key,value)
|
|
|
|
end
|
|
|
|
end
|
2016-05-04 23:23:49 +02:00
|
|
|
end)
|
|
|
|
|