-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.coffee
127 lines (105 loc) · 2.77 KB
/
index.coffee
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
Cylon = require('cylon')
count = 0
curAngle = 0
ANGLE_TO_MOVE = 12
SPEED = 75
TOTAL_CIRCLE = 400
keyHandler = (my, chunk, key) ->
switch chunk
when 'x'
my.sphero.stop()
process.exit()
return
when "s"
my.sphero.setColor 'gold'
when "a"
my.sphero.setColor 'steelblue'
when "d"
my.sphero.setColor 'green'
when 'w'
my.sphero.setColor 'red'
when ' '
my.sphero.stop()
when "\u001b[C" #right
my.sphero.roll SPEED, 90
when "\u001b[B" #back
my.sphero.roll SPEED, 180
when "\u001b[D" #left
my.sphero.roll SPEED, 270
when 'g'
circleA my
else
my.sphero.roll SPEED, 0
return
workFunc = (my) ->
fired = false
my.sphero.stop()
my.sphero.detectCollisions(true)
my.sphero.setRotationRate 50
my.sphero.on 'collision', ->
console.log 'collision'
my.sphero.setColor 0x00BFFF
my.sphero.stop()
return
stdin = process.openStdin()
process.stdin.setEncoding('utf8')
process.stdin.setRawMode(true)
stdin.on 'data', (chunk, key) ->
keyHandler my, chunk, key
return
return
circleA = (my) ->
return if fired
fired = true
circleInterval = every (.25).second(), ->
if curAngle > TOTAL_CIRCLE
clearInterval circleInterval
my.sphero.stop()
return
my.sphero.roll SPEED, curAngle
count++
curAngle += ANGLE_TO_MOVE
afirst = null
totalTime = ((TOTAL_CIRCLE/ANGLE_TO_MOVE) * .25) + 2
after totalTime.second(), ->
SPEED -= 15
my.sphero.setColor 'gold'
my.sphero.roll SPEED, 110
return
after (totalTime+3).second(), ->
my.sphero.stop()
return
after (totalTime + 5).second(), ->
my.sphero.setColor('steelblue')
my.sphero.roll SPEED, 220
return
after (totalTime + 8).second(), ->
my.sphero.stop()
return
# back to halfway for horizontal bar
after (totalTime + 10).second(), ->
my.sphero.roll SPEED, 40
return
after (totalTime + 11.5).second(), ->
my.sphero.stop()
return
after (totalTime + 13.5).second(), ->
my.sphero.setColor 'green'
my.sphero.roll SPEED, 330
return
after (totalTime + 15.5).second(), ->
my.sphero.setColor 'ghostwhite'
my.sphero.stop()
fired = false
return
return
settings =
connection:
name: 'sphero'
adaptor: 'sphero'
port: '/dev/cu.Sphero-RRW-AMP-SPP'
device:
name: 'sphero'
driver: 'sphero'
work: workFunc
Cylon.robot(settings).start()