diff --git a/main.lua b/main.lua index 9854d3a..583db17 100644 --- a/main.lua +++ b/main.lua @@ -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