From fdc1b49c5e6b265cfa12dea2e7eca55f625a05e2 Mon Sep 17 00:00:00 2001 From: Nigel Choi <9gel@users.noreply.github.com> Date: Thu, 15 Aug 2024 20:19:55 +0800 Subject: [PATCH] Now supports 4 channels: RGBW!!! thanks @SadaleNet --- init.lua | 12 ++++++++++-- rgb.html | 24 +++++++++++++++++++++++- rgb.lua | 5 +++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index f5bf937..262c7ff 100644 --- a/init.lua +++ b/init.lua @@ -4,26 +4,34 @@ if file.open("rgb", "r") then R = tonumber(file.readline()) G = tonumber(file.readline()) B = tonumber(file.readline()) + W = tonumber(file.readline()) file.close() + -- Initialize W in case it didn't exist. This would happen in case the state file is of old version + if W==nil then W=1023 end + -- Do not go "back to black"; go to white instead - if R == 1023 and G == 1023 and B == 1023 then R=0 G=0 B=0 end + if R == 1023 and G == 1023 and B == 1023 and W == 1023 then R=0 G=0 B=0 W=0 end pwm.setup(5, 191, R) pwm.start(5) pwm.setup(6, 193, G) pwm.start(6) pwm.setup(7, 197, B) pwm.start(7) + pwm.setup(2, 197, W) + pwm.start(2) end function saveColor() local r = pwm.getduty(5) local g = pwm.getduty(6) local b = pwm.getduty(7) - if R ~= r or G ~= g or B ~= b then + local w = pwm.getduty(2) + if R ~= r or G ~= g or B ~= b or W ~= w then if file.open("rgb", "w") then file.writeline(r) R=r file.writeline(g) G=g file.writeline(b) B=b + file.writeline(w) W=w file.close() end end diff --git a/rgb.html b/rgb.html index fab6479..638e17e 100644 --- a/rgb.html +++ b/rgb.html @@ -58,6 +58,12 @@ #blue::-moz-range-thumb { background: #0000FF; } +#white::-webkit-slider-thumb { + background: #FFFFFF; +} +#white::-moz-range-thumb { + background: #FFFFFF; +} .colorvalue { text-align: center; } @@ -76,6 +82,10 @@