Wakeup lights
Hier de lua scene van de wakeup lights, wel even de id van de rgbw controller veranderen.
--[[
%% properties
%% events
%% globals
--]]
-- Hint: increase parameter 10 of RGBW from default 10 ms to 60 ms for smoother transistions!
-- Wait time in seconds between step changes.
local stepTimeSec = 4
--[[
Setting values for your RGB strip.
Use the sliders on one to get a "nice white" (maximum brightness, pleasing colour).
One of the sliders has to be at 100%, so if we're dealing with an RGBW module, then 100 % means value = 255.
I'm guessing, due to the nature of our eyes and due to the efficiency of LEDs, that the R channel will be set to 100%
Then put the values in the LedStrip table below.
"gamma" smooths step size. Play with values between 1.0 (no gamma) and 3.0 (probably too much).
--]]
local LedStrip={
DeviceID=707,
Rmax=60,
Gmax=190,
Bmax=200,
gamma=1.5}
-- Also toy with these parameters.
local part1=5
local part2=50
local part3=60
-- CODE
local function HueToRGB(m1, m2, h)
if h < 0 then
h = h + 1
elseif h > 1 then
h = h - 1
end
if h < 1/6 then return m1+(m2-m1)*6*h end
if h < 1/2 then return m2 end
if h < 2/3 then return m1+(m2-m1)*(2/3-h)*6
else return m1 end
end
-- h = hue, 0.0 -> 0.33 = red, 0.33 -> 0.66 = green, 0,66 -> 1.0 blue.
-- s = saturation. 0.0 = no saturation, 1.0 = fully saturated
-- l = lightness. 0.0 = no saturation, black; 0.5 = saturated or grey, depending on s; 1.0 = no saturation, white
local function HSLtoRGB(h,s,l)
local m1,m2
if l< 0.5 then
m2=l*(1+s)
else
m2=(l+s)-(s*l)
end
m1=2*l-m2
return HueToRGB(m1, m2, h+1/3),
HueToRGB(m1, m2, h),
HueToRGB(m1, m2, h-1/3)
end
local function SetRGBW(i,h,s,l)
local r,g,b=HSLtoRGB(h,s,l)
-- rgb values range from 0.0 .. 1.0
-- so we need to scale them to 0.255 before sending them to the RGBW controller
r = math.floor(r ^ LedStrip.gamma * LedStrip.Rmax + 0.5)
g = math.floor(g ^ LedStrip.gamma * LedStrip.Gmax + 0.5)
b = math.floor(b ^ LedStrip.gamma * LedStrip.Bmax + 0.5)
-- for debugging
print(string.format(
"Step: %03d HSL: (%05.3f; %05.3f; %05.3f) ==> RGB: (%05.1f; %05.1f; %05.1f).",
i,h,s,l,r,g,b))
fibaro:call(LedStrip.DeviceID, "setColor",r,g,b,"0")
fibaro:sleep(stepTimeSec*1000)
end
-- Dawn simulation is driven by changing hue, saturation and lighntess.
-- This makes the code very compact.
local lightnessSteps=part1+part2+part3
local yellow = 1/6
print("Part 1: Start with red and increase lightness.")
-- Sufficient red is needed, if green LEDS are very efficient.
for i=1,part1 do
SetRGBW(i,0,1,i/lightnessSteps)
end
print("Part 2: Change colour from red to yellow, while")
print("also increasing lightness.")
for i=part1+1,part1+part2 do
SetRGBW(i,yellow*(i-part1)/part2,1,i/lightnessSteps)
end
print("Part 3: Remove saturation, keep hue, while")
print("increasing lightness.")
for i=part1+part2+1,part1+part2+part3 do
SetRGBW(i,yellow,1-(i-part1-part2)/(part3-1),i/lightnessSteps)
end
print("Simulator ends... Turn Off in 5 seconds.")
fibaro:sleep(5000)
SetRGBW(9999,0,0,0)