Description
This is the component provided by the open light block.
Component name: openlight
.
This is the component provided by the open light block.
Component name: openlight
.
setBrightness(brighness:number):number
Set the brightness of the light. Returns the new brightness.
getBrightness():number
Get the brightness of the light.
setColor(color:number):string
Set the light color as an RGB value. Returns the new color as an RGB hex string. Use `tonumber(value, 16)' to convert return value to a usable numeric value.
getColor():string
Get the light color as an RGB hex string. Use `tonumber(value, 16)' to convert return value to a usable numeric value.
Here is a hsv script
light = require("component").openlight
function rgb_to_hex(r, g, b)
-- Ensure values are within 0 to 255 range
r = math.max(0, math.min(255, r))
g = math.max(0, math.min(255, g))
b = math.max(0, math.min(255, b))
return r * 65536 + g * 256 + b
end
function deg_to_hsv(d)
if d < 0 then d = d+360 end
if d > 360 then d = d-360 end
if d > 0 and d < 60 then
return d*4.25
elseif d < 180 then
return 255
elseif d < 240 then
return (240-d)*255
else
return 0
end
end
light.setBrightness(15)
while true do
for n = 0,360,1 do
local r = deg_to_hsv(n+120)
local g = deg_to_hsv(n)
local b = deg_to_hsv(n-120)
light.setColor(rgb_to_hex(r,g,b))
require("os").sleep(0.1)
end
end