From 15a21b78b5b0c4ff149b97a378ffa55089de742d Mon Sep 17 00:00:00 2001 From: ollo Date: Thu, 27 Dec 2018 23:30:39 +0100 Subject: [PATCH] Use round in order to gernerate always an uniq amount of colored characters --- displayword.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/displayword.lua b/displayword.lua index bb08991..c7fe7fe 100644 --- a/displayword.lua +++ b/displayword.lua @@ -56,6 +56,19 @@ function drawLEDs(data, numberNewChars, inverseRow) return tmpBuf end +-- Utility function for round +function round(num) + under = math.floor(num) + upper = math.floor(num) + 1 + underV = -(under - num) + upperV = upper - num + if (upperV > underV) then + return under + else + return upper + end +end + -- Module displaying of the words function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4, characters) -- Set the local variables needed for the colored progress bar @@ -71,7 +84,8 @@ function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, co elseif (words.min4 == 1) then minutes = minutes + 4 end - data.charsPerMinute = math.ceil(characters / minutes) + data.charsPerMinute = round( (characters / minutes) ) + -- devide by five (Minute 0, Minute 1 to Minute 4 takes the last chars) print("Minutes : " .. tostring(minutes) .. " Char minutes: " .. tostring(data.charsPerMinute) ) data.words=words