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 HEX convert script
#6
OK bit of calculation is needed. Here is script which converts 3B RGB in to RGBW and saturation. You could convert it to your needs.

Code:
addressred = '1/1/16' addressgreen = '1/1/17' addressblue = '1/1/18' addresswhite = '1/1/19' addresssaturation = '1/1/20' -- Get Value of RGB picker value = event.getvalue() -- Convert to HEX for splitting to 3 byte values value = lmcore.inttohex(value, 3) -- 3 = number of bytes inside value -- Split First 2 byte HEX values from 3 byte HEX redandgreen = string.sub(value, 1, 4) -- Split First Value from 2 byte HEX red = string.sub(redandgreen, 1, 2) -- Split Last value from 2 byte HEX green = string.sub(redandgreen, -2) -- Split Last byte value from 3 byte HEX blue = string.sub(value, -2) -- Convert HEX values back to integer valuered = lmcore.hextoint (red) valuegreen = lmcore.hextoint (green) valueblue = lmcore.hextoint (blue) -- Calculate lowest value of RGB value low = math.min(unpack({valuered, valuegreen, valueblue})) -- Calculate highest value of RGB value high = math.max(unpack({valuered, valuegreen, valueblue})) -- Calculate Saturation (The saturation is the colorfulness of a color relative to its own brightness) The difference between the last two variables divided by the highest is the saturation. saturation = math.floor((100 * ((high - low) / high)) + 0.5) if valuered == 0 and valuegreen == 0 and valueblue == 0 then  white = 0 else  white = math.floor(((255 - saturation) / 255 * (valuered + valuegreen + valueblue) / 3)+ 0.5) end -- Write integer RGB values and Calculated White & Saturation to KNX grp.update(addressred, math.floor((valuered / 2.55) + 0.5)) grp.update(addressgreen, math.floor((valuegreen / 2.55) + 0.5)) grp.update(addressblue, math.floor((valueblue / 2.55) + 0.5)) grp.update(addresswhite, math.floor((white / 2.55) + 0.5)) grp.update(addresssaturation, saturation)
BR
------------------------------
Ctrl+F5
Reply


Messages In This Thread
RGB to HEX convert script - by Jayce - 15.05.2018, 12:59
RE: RGB to HEX convert script - by Daniel - 15.05.2018, 14:14
RE: RGB to HEX convert script - by Jayce - 16.05.2018, 09:04
RE: RGB to HEX convert script - by Daniel - 16.05.2018, 09:09
RE: RGB to HEX convert script - by Jayce - 16.05.2018, 09:14
RE: RGB to HEX convert script - by Daniel - 16.05.2018, 09:56
RE: RGB to HEX convert script - by Jayce - 16.05.2018, 12:48

Forum Jump: