2013-11-24 01:15:44 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-12-03 16:48:20 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
2014-05-23 12:20:16 +08:00
|
|
|
"github.com/hybridgroup/gobot/platforms/sphero"
|
|
|
|
"time"
|
2013-11-24 01:15:44 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-05-23 12:20:16 +08:00
|
|
|
master := gobot.NewGobot()
|
2013-11-25 06:56:13 +08:00
|
|
|
|
|
|
|
spheros := map[string]string{
|
2013-12-04 02:43:22 +08:00
|
|
|
"Sphero-BPO": "/dev/rfcomm0",
|
2013-11-25 06:56:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for name, port := range spheros {
|
2014-05-23 12:20:16 +08:00
|
|
|
spheroAdaptor := sphero.NewSpheroAdaptor("sphero", port)
|
2013-11-25 06:56:13 +08:00
|
|
|
|
2014-05-23 12:20:16 +08:00
|
|
|
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor, "sphero")
|
2013-11-25 06:56:13 +08:00
|
|
|
|
|
|
|
work := func() {
|
2014-04-29 02:40:20 +08:00
|
|
|
spheroDriver.SetRGB(uint8(255), uint8(0), uint8(0))
|
2013-11-25 06:56:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-23 12:20:16 +08:00
|
|
|
master.Robots = append(master.Robots,
|
|
|
|
gobot.NewRobot(name, []gobot.Connection{spheroAdaptor}, []gobot.Device{spheroDriver}, work))
|
2013-11-25 06:56:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-23 12:20:16 +08:00
|
|
|
master.Robots = append(master.Robots, gobot.NewRobot(
|
2014-06-07 04:18:07 +08:00
|
|
|
"",
|
2014-05-23 12:20:16 +08:00
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
func() {
|
|
|
|
gobot.Every(1*time.Second, func() {
|
2014-06-09 10:37:41 +08:00
|
|
|
gobot.Call(master.Robot("Sphero-BPO").Device("sphero").Driver, "SetRGB", uint8(gobot.Rand(255)), uint8(gobot.Rand(255)), uint8(gobot.Rand(255)))
|
2013-11-25 06:56:13 +08:00
|
|
|
})
|
|
|
|
},
|
2014-05-23 12:20:16 +08:00
|
|
|
))
|
2013-11-25 06:56:13 +08:00
|
|
|
|
2013-11-25 08:24:32 +08:00
|
|
|
master.Start()
|
2013-11-24 01:15:44 +08:00
|
|
|
}
|