Sha256: 99af566fc739bc8b2e362ff923b7c05e08081adbed9bdbabcfd87216c92abed9

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

#!/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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
milight-easybulb-1.0.0 bin/example