-
Notifications
You must be signed in to change notification settings - Fork 1
/
example
executable file
·74 lines (60 loc) · 1.38 KB
/
example
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'milight'
if ARGV.length != 1
puts "Usage: #{$PROGRAM_NAME} <ip_address>"
puts ' For example:', " #{$PROGRAM_NAME} 192.168.0.10"
exit 1
end
ip = ARGV.shift
lights = Milight::Controller.new ip
red = '#f00'
green = '#0f0'
blue = '#00f'
yellow = '#ff0'
# Control all lights on all channels
lights.all.on
sleep 1
lights.all.colour(red)
sleep 1
lights.all.colour(green)
sleep 1
lights.all.colour(blue)
sleep 1
lights.all.off
sleep 1
# Control each channel/group of lights
lights.group(1).colour(red)
lights.group(2).colour(green)
lights.group(3).colour(yellow)
lights.group(4).colour(blue)
sleep 1
# Assign the group to a variable for easier identification
bedroom = lights.group(1)
kitchen = lights.group(2)
bedroom.colour('#2F22ff')
kitchen.colour('#FFF')
# Set either the hue or brightness without affecting the other
lights.group(3).hue(yellow)
lights.group(4).brightness(25) # given as a percentage
sleep 1
lights.all.off
sleep 3
# Lets simulate the sunrise!
all = lights.all
SUNRISE = %w[ #003 #026 #02A #23A #F50 #F92 #FC0 #FF4 #FFF]
puts 'Sunrise!'
SUNRISE.each do |colour|
all.colour(colour)
print '.'
sleep 2
end
puts 'Sunset!'
SUNRISE.reverse_each do |colour|
all.colour(colour)
print '.'
sleep 2
end
sleep 1
# ...and set everything back to white when we're done!
lights.all.white