【问题标题】:How to make LIFX bulbs flicker如何使 LIFX 灯泡闪烁
【发布时间】:2014-08-05 03:48:47
【问题描述】:

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

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

LIFX Website

LIFX Gem on Github

【问题讨论】:

  • Github 网站上有示例代码,那么您尝试使用它的时候是什么问题?还是你在尝试之前问过?
  • 打开或关闭它们可以正常工作,set_color 可以正常工作,我没有找到任何使它们闪烁的方法。如果你看到任何请告诉我

标签: ruby gem lifx


【解决方案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/

【讨论】:

    猜你喜欢
    • 2016-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-16
    • 1970-01-01
    • 1970-01-01
    • 2021-07-17
    相关资源
    最近更新 更多