From 0c8ab7155f3d34ac0bf0faf3e007c9e360f23347 Mon Sep 17 00:00:00 2001 From: ollo Date: Tue, 7 Jun 2016 23:30:13 +0200 Subject: [PATCH] LEDs are controlled --- main.lua | 156 ++++++++++++++++++++++++++++++++++++++++++++++++-- wordclock.lua | 10 ++-- 2 files changed, 157 insertions(+), 9 deletions(-) diff --git a/main.lua b/main.lua index 583db17..71b8261 100644 --- a/main.lua +++ b/main.lua @@ -26,16 +26,162 @@ tmr.alarm(0, 100, 1, function() end) function generateLEDs(words) - buf="" - if (words.min4 == 1) then - buf=string.char(0,0,50):rep(110) + + 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=string.char(0,0,0):rep(110) + 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 + if (words.min4 == 1) then + buf= buf .. color:rep(1) + else + buf= buf .. white:rep(1) end return buf end -tmr.alarm(1, 1000, 1 ,function() +tmr.alarm(1, 5000, 1 ,function() sec, usec = rtctime.get() time = getTime(sec, timezoneoffset) print("Time : " , sec) diff --git a/wordclock.lua b/wordclock.lua index 8dc143d..4efb779 100755 --- a/wordclock.lua +++ b/wordclock.lua @@ -1,6 +1,8 @@ -- Revese engeeniered code of display_wc_ger.c by Vlad Tepesch -- See https://www.mikrocontroller.net/articles/Word_Clock_Variante_1#Download +-- TODO: Also add the twenty as return value! + -- Return the leds to use -- the granuality is 5 minutes function display_timestat(hours, minutes, longmode) @@ -9,8 +11,9 @@ function display_timestat(hours, minutes, longmode) end -- generate an empty return type - local ret = { itis=0, fiveMin=0, tenMin=0, after=0, before=0, threeHour=0, quater=0, half=0, s=0, + local ret = { itis=0, fiveMin=0, tenMin=0, after=0, before=0, threeHour=0, quater=0, threequater=0, half=0, s=0, one=0, two=0, three=0, four=0, five=0, six=0, seven=0, eight=0, nine=0, ten=0, eleven=0, twelve=0, + twenty=0, clock=0, sr_nc=0, min1=0, min2=0, min3=0, min4=0 } -- return black screen if there is no real time given @@ -59,9 +62,8 @@ function display_timestat(hours, minutes, longmode) ret.tenMin=1 ret.half=1 ret.after=1 - elseif (minutes==9) then - ret.quater=1 - ret.before=1 + elseif (minutes==9) then + ret.threequater=1 elseif (minutes==10) then ret.tenMin=1 ret.before=1