forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sphero_master.go
50 lines (38 loc) · 927 Bytes
/
sphero_master.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
46
47
48
49
50
package main
import (
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/sphero"
)
func main() {
gbot := gobot.NewGobot()
spheros := map[string]string{
"Sphero-BPO": "/dev/rfcomm0",
}
for name, port := range spheros {
spheroAdaptor := sphero.NewSpheroAdaptor("sphero", port)
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor, "sphero")
work := func() {
spheroDriver.SetRGB(uint8(255), uint8(0), uint8(0))
}
robot := gobot.NewRobot(name,
[]gobot.Connection{spheroAdaptor},
[]gobot.Device{spheroDriver},
work,
)
gbot.AddRobot(robot)
}
robot := gobot.NewRobot("",
func() {
gobot.Every(1*time.Second, func() {
sphero := gbot.Robot("Sphero-BPO").Device("sphero").(*sphero.SpheroDriver)
sphero.SetRGB(uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
)
})
},
)
gbot.AddRobot(robot)
gbot.Start()
}