Round percentage of adc

This commit is contained in:
ollo 2019-04-27 00:14:27 +02:00
parent aeb5dab9fd
commit a11f756c42

View File

@ -57,7 +57,7 @@ function generateLEDs(words, colorForground, colorMin1, colorMin2, colorMin3, co
end end
if (adc ~= nil) then if (adc ~= nil) then
local per = (100*adc.read(0)/1024) local per = (100*adc.read(0)/1024)
briPercent = ( ((briPercent * 4) + per) / 5) briPercent = math.floor( ((briPercent * 4) + per) / 5)
print("Minutes : " .. tostring(minutes) .. " bright: " .. tostring(briPercent) .. "% current: " .. tostring(per) .. "%") print("Minutes : " .. tostring(minutes) .. " bright: " .. tostring(briPercent) .. "% current: " .. tostring(per) .. "%")
data.colorFg = string.char(string.byte(colorForground,1) * briPercent / 100, string.byte(colorForground,2) * briPercent / 100, string.byte(colorForground,3) * briPercent / 100) data.colorFg = string.char(string.byte(colorForground,1) * briPercent / 100, string.byte(colorForground,2) * briPercent / 100, string.byte(colorForground,3) * briPercent / 100)
data.colorMin1 = string.char(string.byte(colorMin1,1) * briPercent / 100, string.byte(colorMin1,2) * briPercent / 100, string.byte(colorMin1,3) * briPercent / 100) data.colorMin1 = string.char(string.byte(colorMin1,1) * briPercent / 100, string.byte(colorMin1,2) * briPercent / 100, string.byte(colorMin1,3) * briPercent / 100)