-
Notifications
You must be signed in to change notification settings - Fork 1
/
sunrise.rb
44 lines (34 loc) · 910 Bytes
/
sunrise.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'lifx'
label = ARGV[0]
time = ARGV[1] ||= 120
client = LIFX::Client.lan
client.discover! do |c|
c.lights.with_label(label)
end
client.lights.turn_on
light = client.lights.with_label(label)
fade_time = time # time in seconds
interval = 6 # run every 6 seconds
increment = fade_time/interval
luminence = 0.01
luminence_increment = 1/increment.to_f
hue_increment = 60/increment # Fade from red to bright yellow 0 to 60
hue = hue_increment
light.set_color(LIFX::Color.hsl(0, 1, luminence), duration: interval)
def set_interval(delay)
Thread.new do
loop do
sleep delay
yield
end
end
end
sunrise = set_interval(interval) do
if luminence >= 1
sunrise.kill
end
light.set_color(LIFX::Color.hsl(hue, 1, luminence), duration: interval)
luminence = luminence + luminence_increment
hue = hue + hue_increment
end
sunrise.join