From b252453f1e3df4559f5a543245e5382110a0df6d Mon Sep 17 00:00:00 2001 From: ollo Date: Sun, 22 May 2016 15:31:43 +0200 Subject: [PATCH] Extracted LED generation into seperate function --- main.lua | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) 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