forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsphero_multiple.go
45 lines (35 loc) · 998 Bytes
/
sphero_multiple.go
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
package main
import (
"fmt"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/sphero"
"time"
)
func main() {
master := gobot.NewGobot()
spheros := []string{
"/dev/rfcomm0",
"/dev/rfcomm1",
"/dev/rfcomm2",
"/dev/rfcomm3",
}
for s := range spheros {
spheroAdaptor := sphero.NewSpheroAdaptor("Sphero", spheros[s])
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor, "Sphero"+spheros[s])
work := func() {
spheroDriver.Stop()
gobot.On(spheroDriver.Events["Collision"], func(data interface{}) {
fmt.Println("Collision Detected!")
})
gobot.Every(1*time.Second, func() {
spheroDriver.Roll(100, uint16(gobot.Rand(360)))
})
gobot.Every(3*time.Second, func() {
spheroDriver.SetRGB(uint8(gobot.Rand(255)), uint8(gobot.Rand(255)), uint8(gobot.Rand(255)))
})
}
master.Robots = append(master.Robots,
gobot.NewRobot("sphero", []gobot.Connection{spheroAdaptor}, []gobot.Device{spheroDriver}, work))
}
master.Start()
}