我们购买了几个LIFX灯泡,我要求根据某些事件编写ruby代码来制作LIFX闪烁。
我找不到任何让它闪烁的例子,谁知道怎么样?一些使用官方gem的代码示例将非常感激
答案 0 :(得分:1)
安装了lifx gem后,您可以试试这个:
require 'lifx'
# set the label of the bulb you want to "flicker"
label = 'YourBulbLabel'
client = LIFX::Client.lan
# find the light with the label you have set in your LAN
client.discover! do |c|
c.lights.with_label(label)
end
# turn on the lights
client.lights.turn_on
light = client.lights.with_label(label)
# make it flicker
light.set_color(LIFX::Color.hsbk(259, 0.1, 0.5, 5000), duration: 1)
sleep 1
light.set_color(LIFX::Color.hsbk(259, 1, 1, 5000), duration: 1)
sleep 1
light.set_color(LIFX::Color.hsbk(259, 0.1, 0.5, 5000), duration: 1)
sleep 1
希望这能让你开始 文档帮助了我很多:http://www.rubydoc.info/github/lifx/lifx-gem/master/LIFX/