Added brightness dimming

This commit is contained in:
ollo 2019-04-19 23:38:46 +02:00
parent e5d7ec016b
commit e33ad2639e

View File

@ -42,7 +42,7 @@ function drawLEDs(data, numberNewChars, inverseRow)
if (numberNewChars == nil) then if (numberNewChars == nil) then
numberNewChars=0 numberNewChars=0
end end
print(tostring(numberNewChars) .. " charactes " .. tostring(data.charsPerMinute) .. " per minute; " .. tonumber(data.drawnCharacters) .. " used characters") --print(tostring(numberNewChars) .. " charactes " .. tostring(data.charsPerMinute) .. " per minute; " .. tonumber(data.drawnCharacters) .. " used characters")
local tmpBuf=nil local tmpBuf=nil
for i=1,numberNewChars do for i=1,numberNewChars do
if (tmpBuf == nil) then if (tmpBuf == nil) then
@ -69,6 +69,9 @@ function round(num)
end end
end end
-- Initial value of percentage
briPercent=50
-- Module displaying of the words -- Module displaying of the words
function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4, characters) function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, colorMin4, characters)
-- Set the local variables needed for the colored progress bar -- Set the local variables needed for the colored progress bar
@ -86,13 +89,14 @@ function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, co
end end
data.charsPerMinute = round( (characters / minutes) ) data.charsPerMinute = round( (characters / minutes) )
if (adc ~= nil) then if (adc ~= nil) then
briPercent=(100*adc.read(0)/900) local per = (100*adc.read(0)/1024)
print("Minutes : " .. tostring(minutes) .. " Char minutes: " .. tostring(data.charsPerMinute) .. " bright: " .. tostring(briPercent) .. "%") briPercent = ( ((briPercent * 4) + per) / 5)
data.colorFg = colorForground print("Minutes : " .. tostring(minutes) .. " Char minutes: " .. tostring(data.charsPerMinute) .. " bright: " .. tostring(briPercent) .. "% " .. tostring(per) .. "%")
data.colorMin1 = colorMin1 data.colorFg = string.char(string.byte(colorForground,1) * briPercent / 100, string.byte(colorForground,2) * briPercent / 100, string.byte(colorForground,3) * briPercent / 100)
data.colorMin2 = colorMin2 data.colorMin1 = string.char(string.byte(colorMin1,1) * briPercent / 100, string.byte(colorMin1,2) * briPercent / 100, string.byte(colorMin1,3) * briPercent / 100)
data.colorMin3 = colorMin3 data.colorMin2 = string.char(string.byte(colorMin2,1) * briPercent / 100, string.byte(colorMin2,2) * briPercent / 100, string.byte(colorMin2,3) * briPercent / 100)
data.colorMin4 = colorMin4 data.colorMin3 = string.char(string.byte(colorMin3,1) * briPercent / 100, string.byte(colorMin3,2) * briPercent / 100, string.byte(colorMin3,3) * briPercent / 100)
data.colorMin4 = string.char(string.byte(colorMin4,1) * briPercent / 100, string.byte(colorMin4,2) * briPercent / 100, string.byte(colorMin4,3) * briPercent / 100)
else else
-- devide by five (Minute 0, Minute 1 to Minute 4 takes the last chars) -- devide by five (Minute 0, Minute 1 to Minute 4 takes the last chars)
print("Minutes : " .. tostring(minutes) .. " Char minutes: " .. tostring(data.charsPerMinute) ) print("Minutes : " .. tostring(minutes) .. " Char minutes: " .. tostring(data.charsPerMinute) )