I already know how to use RGB datatype (by a little tutorial by schneider), so I can split the value to the 3 objects (Red, Green, Blue) and viceversa.
Now how I can do with RGB-white?
And I tested it on visualization but it seems to me a little confusion
-- Split
R = bit.rshift(bit.band(value,0xff000000),24)
G = bit.rshift(bit.band(value,0x00ff0000),16)
B = bit.rshift(bit.band(value,0x0000ff00),8)
W = bit.band(value,0x000000ff)
-- Merge
RGBW = R * 0x1000000 + G * 0x10000 + B * 0x100 + W
-- Split
R = bit.rshift(bit.band(value,0xff000000),24)
G = bit.rshift(bit.band(value,0x00ff0000),16)
B = bit.rshift(bit.band(value,0x0000ff00),8)
W = bit.band(value,0x000000ff)
-- Merge
RGBW = R * 0x1000000 + G * 0x10000 + B * 0x100 + W
BR,
Erwin
I think there is a little mistake in that code because the colors shown by the icon don't match both ways: splitting and merging.
value = event.getvalue() ---- from 32/1/20 icon address
-- Split
R = bit.rshift(bit.band(value,0xff000000),24)
G = bit.rshift(bit.band(value,0x00ff0000),16)
B = bit.rshift(bit.band(value,0x0000ff00),8)
W = bit.band(value,0x000000ff)
if R ~= grp.getvalue('32/3/1') then
grp.update('32/3/1', R)
alert®
end
if R ~= grp.getvalue('32/3/2') then
grp.update('32/3/2', G)
alert(G)
end
if R ~= grp.getvalue('32/3/3') then
grp.update('32/3/3', B)
alert(B)
end
if R ~= grp.getvalue('32/3/4') then
grp.update('32/3/4', W)
alert(W)
end
That's all. Still, there is a visualization issue like a reattach here
Add this to both of your scripts to prevent loops:
Code:
if event.sender == 'se' then
return
end
You should also use grp.checkupdate() instead of grp.getvalue/grp.getvalue, you already have copy-paste errors where you compare R with all other components.
Add this to both of your scripts to prevent loops:
Code:
if event.sender == 'se' then
return
end
You should also use grp.checkupdate() instead of grp.getvalue/grp.getvalue, you already have copy-paste errors where you compare R with all other components.
OK! Now everything is fine, thank you so much!
Just to a better understanding: what is the core difference between grp.checkupdate, grp.getvalue and grp.update?
See Lua documentation here: https://openrb.com/docs/lua.htm#grp.checkwrite
The basic idea is to write less code by using built-in functions instead of writing more complex code, which leads to more possible errors.
25.08.2020, 15:43 (This post was last modified: 25.08.2020, 15:44 by Erwin van der Zwart.)
Hi,
I think your issue with the merge is in the 5.001 scale objects as they return 0-100 within the script engine instead of 0-255, when you split/merge a RGBW value you will have 0-255 format so you might want to use a calculation R = math.round((R * 2.55),0) before pushing it to the merge calculation (and do the same with other 3 colors)
redGroup = '1/1/1' --- modify ether group address or name of group
greenGroup = 'LED1 Green Status' --- modify ether group address or name of group
blueGroup = '1/1/3' --- modify ether group address or name of group
whiteGroup = '1/1/4'
rgbwGroup = 'RGB Value' --- modify ether group address or name of group
I think your issue with the merge is in the 5.001 scale objects as they return 0-100 within the script engine instead of 0-255, when you split/merge a RGBW value you will have 0-255 format so you might want to use a calculation R = math.round((R * 2.55),0) before pushing it to the merge calculation (and do the same with other 3 colors)
BR,
Erwin
yes, I noticed it and fixed, thanks.
Here another issue with visualization (see attached pic): what are the black spot on preset? How to avoid that?