Skip to content

Commit

Permalink
minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
docwhat committed Feb 10, 2014
1 parent ecf45a1 commit 1debc30
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions examples/colors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#
# The light sensor must be on port 1
require 'lego_nxt'
require 'ap'

brick = LegoNXT::Brick.new
color_sensor = LegoNXT::Sensors::ColorSensor.new
Expand All @@ -17,14 +16,20 @@
:blue
]

(colors + colors).shuffle.each do |color|
puts "Setting color to #{color}"
color_sensor.color color
(1..5).each do |i|
sleep(i.to_f / 10)
ap color_sensor.value
begin
(colors + colors).shuffle.each do |color|
puts "Setting color to #{color}"
color_sensor.color color
(1..5).each do |i|
sleep(i.to_f / 10)
value = color_sensor.value
fail 'You need the color sensor plugged into port 1' if value.nil?
puts " #{value}"
end
end
rescue Interrupt
puts 'You quit it'
ensure
# Turns the light off
color_sensor.color :passive
end

# Turns it off
color_sensor.color :passive

0 comments on commit 1debc30

Please sign in to comment.