Skip to content

Instantly share code, notes, and snippets.

@davidwkeith
Created February 6, 2016 21:09
Show Gist options
  • Save davidwkeith/3c2654cd0e3bb00afec8 to your computer and use it in GitHub Desktop.
Save davidwkeith/3c2654cd0e3bb00afec8 to your computer and use it in GitHub Desktop.

Revisions

  1. davidwkeith created this gist Feb 6, 2016.
    23 changes: 23 additions & 0 deletions flickering.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    require 'hue'

    CANDLE_COLOR_RANGE = [*2000..2200] # Kelvin, 2000K is lowest Hue can do
    CANDLE_BRIGHTNESS_RANGE = [*20..52]

    bridge = Hue.application

    candle = Hue::Bulb.new(bridge, 1)

    candle.on if candle.off?


    loop do
    begin
    candle.color = Hue::Colors::ColorTemperature.new CANDLE_COLOR_RANGE.sample
    candle.brightness = CANDLE_BRIGHTNESS_RANGE.sample
    @delay = (rand * 0.2200) + 0.08
    rescue
    puts 'delaying 2 seconds'
    @delay = 2
    end
    sleep @delay
    end