LogicMachine Forum
Random RGB color script for LM Ambient - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Random RGB color script for LM Ambient (/showthread.php?tid=157)



Random RGB color script for LM Ambient - edgars - 09.12.2015

1. Specify RGB grp address in LM-Wall --> LED config
2. Add the following Resident script with 0 interval

Code:
math.randomseed(os.time()) function init_color()    color = {}    color.r = math.random(0,10)*25    color.g = math.random(0,10)*25    color.b = math.random(0,10)*25    return color end function RGB(r,g,b)     color = 0    color = bit.lshift(bit.band(r,0xFF),16) + bit.lshift(bit.band(g,0xFF),8) + bit.band(b,0xFF)    return color end function linear(c1,c2,k)    return (c2 - c1)*k + c1 end if src == nil then    src = init_color() end dst = init_color() time = 4 delay = 0.2 steps = time/delay k = time / delay for i = 0,steps do    r = linear(src.r,dst.r,i/steps)    g = linear(src.g,dst.g,i/steps)    b = linear(src.b,dst.b,i/steps)   end        grp.update('RGB LED',RGB(r,g,b))    os.sleep(delay)             end src = dst os.sleep(delay)