Lua RGB 控制脚本

Lua script for RGB control

我最近下载了 an RGB program for the LEDs in my computer. The program lets you create scripts for the lighting. I'm looking to create something like this (a colour fade cycle),但由于我之前没有在 Lua 中编码,所以我要从其他示例脚本开始。这是我目前拥有的:

`-- Variables

local delay = 10 -- this is the update rate, in milliseconds
local colour_step = 1.1

--
Lighting.SetStepDuration(200)
Lighting.SetFlashingSpeed(0)
Lighting.SetBreathingModeEnabled(false)

--local r = 15
--local g = 0
--local b = 0

local r, g, b = Lighting.ColourUtils.HSVtoRGB(0, 0.0933, 1)

while true do
    if r > 0 and b == 0 then
        r = r - 1
    g = g + 1
    end
    if g > 0 and r == 0 then
        g = g - 1
    b = b + 1
    end
    if b > 0 and g == 0 then
        b = b - 1
    r = r + 1
    end

    r = tonumber(("%x"):format(r * 15), 16)
    g = tonumber(("%x"):format(g * 15), 16)
    b = tonumber(("%x"):format(b * 15), 16)

    Lighting.BatchBegin()
    for i = 1, 8 do
        Lighting.SetColour(i, r, g, b)
    end
    Lighting.BatchEnd()
    os.sleep(delay)
end'

出现错误:

bad argument #2 to 'SetColour' (value is out of range (range is 0x0-0xF))

如有任何帮助,我将不胜感激。提前致谢。

我认为错误很明显:可接受的颜色值范围是 0-15,但您传递的值超出了该范围。看起来您可以简单地删除 r = tonumber(("%x"):format(r * 15), 16) 行,因为它与 r = r * 15 相同,您的情况可能不需要。