This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

RGB to separate objects
#2
Hi, I asked your question to the chatgpt AI and got a working result, hope this works for you too.
Function to convert KNX RGB datatype to separate 1-byte values:

Code:
function knxRGBToBytes(knxRGB)
    local red = bit.rshift(bit.band(knxRGB, 0xFF0000), 16)
    local green = bit.rshift(bit.band(knxRGB, 0x00FF00), 8)
    local blue = bit.band(knxRGB, 0x0000FF)
    return red, green, blue
end
-- Example usage
local knxRGB = grp.getvalue('x/x/x')
local red, green, blue = knxRGBToBytes(knxRGB)
log(red, green, blue)


The other function convert separate 1-byte values to KNX RGB datatype:

Code:
function bytesToKNXRGB(red, green, blue)
    local knxRGB = bit.lshift(red, 16) + bit.lshift(green, 8) + blue
    return knxRGB
end

-- Example usage
local red, green, blue = 255, 102, 51
local knxRGB = bytesToKNXRGB(red, green, blue)
log(string.format("%X", knxRGB))
Reply


Messages In This Thread
RGB to separate objects - by tomnord - 14.01.2023, 10:24
RE: RGB to separate objects - by tigi - 14.01.2023, 16:28

Forum Jump: