2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2013-11-24 01:15:44 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-07-11 08:21:21 +08:00
|
|
|
"time"
|
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/platforms/sphero"
|
2013-11-24 01:15:44 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-19 03:08:25 +08:00
|
|
|
master := gobot.NewMaster()
|
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 {
|
2016-10-03 22:58:43 +08:00
|
|
|
spheroAdaptor := sphero.NewAdaptor(port)
|
|
|
|
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
|
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-07-09 09:36:14 +08:00
|
|
|
robot := gobot.NewRobot(name,
|
|
|
|
[]gobot.Connection{spheroAdaptor},
|
|
|
|
[]gobot.Device{spheroDriver},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
master.AddRobot(robot)
|
2013-11-25 06:56:13 +08:00
|
|
|
}
|
|
|
|
|
2014-07-09 09:36:14 +08:00
|
|
|
robot := gobot.NewRobot("",
|
2014-05-23 12:20:16 +08:00
|
|
|
func() {
|
|
|
|
gobot.Every(1*time.Second, func() {
|
2016-10-19 03:08:25 +08:00
|
|
|
sphero := master.Robot("Sphero-BPO").Device("sphero").(*sphero.SpheroDriver)
|
2014-07-09 09:36:14 +08:00
|
|
|
sphero.SetRGB(uint8(gobot.Rand(255)),
|
|
|
|
uint8(gobot.Rand(255)),
|
|
|
|
uint8(gobot.Rand(255)),
|
|
|
|
)
|
2013-11-25 06:56:13 +08:00
|
|
|
})
|
|
|
|
},
|
2014-07-09 09:36:14 +08:00
|
|
|
)
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
master.AddRobot(robot)
|
2013-11-25 06:56:13 +08:00
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
master.Start()
|
2013-11-24 01:15:44 +08:00
|
|
|
}
|