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 relative dimming from KNX
#9
(09.11.2020, 08:56)admin Wrote: Use this event script for 4-bit object. Change R/G/B addresses as needed and modify step and delay to change the dimming speed and smoothness.

Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
raddr = '32/1/1' -- red value address gaddr = '32/1/2' -- green value address baddr = '32/1/3' -- blue value address step = 0.05 -- step side delay = 0.3 -- delay between steps value = event.getvalue() up = bit.band(value, 0x08) == 0x08 stop = bit.band(value, 0x07) == 0 if stop then   return  end -- get value and convert from 0..100 to 0..255 r = grp.getvalue(raddr) * 2.55 g = grp.getvalue(gaddr) * 2.55 b = grp.getvalue(baddr) * 2.55 function rgbtohsv(r, g, b)   local max, min, d, h, s, v   max = math.max(r, g, b)   min = math.min(r, g, b)   d = max - min   s = max == 0 and 0 or (d / max)   v = max / 255   if max == min then     h = 0   elseif max == r then     h = (g - b) + d * (g < b and 6 or 0)     h = h / (6 * d)   elseif max == g then     h = (b - r) + d * 2     h = h / (6 * d)   elseif max == b then     h = (r - g) + d * 4     h = h / (6 * d)   end   return h, s, v end function hsvtorgb(h, s, v)   local r, g, b, i, f, p, q, t, z   i = math.floor(h * 6)   f = h * 6 - i   p = v * (1 - s)   q = v * (1 - f * s)   t = v * (1 - (1 - f) * s)   z = i % 6   if z == 0 then     r = v     g = t     b = p   elseif z == 1 then     r = q     g = v     b = p   elseif z == 2 then     r = p     g = v     b = t   elseif z == 3 then     r = p     g = q     b = v   elseif z == 4 then     r = t     g = p     b = v   elseif z == 5 then     r = v     g = p     b = q   end   r = math.round(r * 255)   g = math.round(g * 255)   b = math.round(b * 255)   return r, g, b end function rgbstep(r, g, b, up, step)   local h, s, v = rgbtohsv(r, g, b)   local v2 = up and math.min(1, v + step) or math.max(0, v - step)     if v == v2 then     return   end   return hsvtorgb(h, s, v2) end while true do   r, g, b = rgbstep(r, g, b, up, step)   if r then     grp.write(raddr, r, dt.uint8)     grp.write(gaddr, g, dt.uint8)     grp.write(baddr, b, dt.uint8)   else     break   end   os.sleep(delay)   newvalue = grp.getvalue(event.dst)   if value ~= newvalue then     break   end end
Awesome! Thank you very much!!
Reply


Messages In This Thread
RGB relative dimming from KNX - by alexll - 01.11.2020, 23:52
RE: RGB relative dimming from KNX - by Daniel - 02.11.2020, 14:57
RE: RGB relative dimming from KNX - by alexll - 02.11.2020, 15:30
RE: RGB relative dimming from KNX - by alexll - 03.11.2020, 19:20
RE: RGB relative dimming from KNX - by admin - 04.11.2020, 07:48
RE: RGB relative dimming from KNX - by alexll - 04.11.2020, 10:55
RE: RGB relative dimming from KNX - by alexll - 07.11.2020, 19:37
RE: RGB relative dimming from KNX - by admin - 09.11.2020, 08:56
RE: RGB relative dimming from KNX - by alexll - 09.11.2020, 21:31

Forum Jump: