forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsphero_api.go
38 lines (28 loc) · 874 Bytes
/
sphero_api.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
package main
import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/api"
"github.com/hybridgroup/gobot/platforms/sphero"
)
var Master *gobot.Gobot
func main() {
Master = gobot.NewGobot()
api.NewAPI(Master).Start()
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)
robot.AddCommand("TurnBlue", func(params map[string]interface{}) interface{} {
spheroDriver.SetRGB(uint8(0), uint8(0), uint8(255))
return nil
})
Master.Robots = append(Master.Robots, robot)
}
Master.Start()
}