0

我们买了几个 LIFX 灯泡,我要求编写 ruby​​ 代码来根据某些事件使 LIFX 闪烁。

我找不到任何让它闪烁的例子,有人知道怎么做吗?一些使用官方 gem 的代码示例将不胜感激

LIFX 网站

Github 上的 LIFX 宝石

4

1 回答 1

1

once you have installed the lifx gem you can try this:

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

hope this gets you started the documentation helped me a lot: http://www.rubydoc.info/github/lifx/lifx-gem/master/LIFX/

于 2015-01-08T21:32:25.360 回答