-
Notifications
You must be signed in to change notification settings - Fork 1
/
workshop.rb
62 lines (44 loc) · 856 Bytes
/
workshop.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Lets hide some not so nice stuff
require 'rubygems'
require 'bundler/setup'
Bundler.setup
require 'sphero'
require './device' if File.exists? './device.rb'
require 'io/console'
class Sphero
def self.connect(device = Device::PATH)
s = new(device)
at_exit do
s.close
end
if block_given?
begin
yield s
ensure
s.close
nil
end
else
s
end
end
def calibrate
puts "Set the heading and press space ..."
self.back_led_output = 255
self.color('black')
loop do
c = $stdin.getch
case c
when "a", "D"
self.heading = -5
when "d", "C"
self.heading = +5
when " ", "\r"
break
end
end
back_led_output = 0
self.color('blue')
self.puts "Calibration finished"
end
end