Extracted LED generation into seperate function

This commit is contained in:
ollo 2016-05-22 15:31:43 +02:00
parent 309641c023
commit b252453f1e

View File

@ -25,6 +25,15 @@ tmr.alarm(0, 100, 1, function()
end
end)
function generateLEDs(words)
buf=""
if (words.min4 == 1) then
buf=string.char(0,0,50):rep(110)
else
buf=string.char(0,0,0):rep(110)
end
return buf
end
tmr.alarm(1, 1000, 1 ,function()
sec, usec = rtctime.get()
@ -33,17 +42,9 @@ tmr.alarm(1, 1000, 1 ,function()
print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second)
words = display_timestat(time.hour, time.minute)
-- All Leds are off
buf=string.char(0,0,0):rep(110)
if (words.min4 == 1) then
buf=string.char(0,0,50):rep(110)
else
buf=string.char(0,0,0):rep(110)
end
ws2812.write(4, buf)
ledBuf = generateLEDs(words)
-- Write the buffer to the LEDs
ws2812.write(4, ledBuf)
for key,value in pairs(words) do
if (value > 0) then