2013-11-24 01:15:44 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-12-03 16:48:20 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
// "github.com/hybridgroup/gobot-sphero"
|
2013-11-24 01:15:44 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2013-11-25 08:24:32 +08:00
|
|
|
master := gobot.GobotMaster()
|
2013-11-25 06:56:13 +08:00
|
|
|
|
|
|
|
spheros := map[string]string{
|
|
|
|
"Sphero-BPO": "127.0.0.1:4560",
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, port := range spheros {
|
|
|
|
spheroAdaptor := new(gobotSphero.SpheroAdaptor)
|
|
|
|
spheroAdaptor.Name = "sphero"
|
|
|
|
spheroAdaptor.Port = port
|
|
|
|
|
|
|
|
sphero := gobotSphero.NewSphero(spheroAdaptor)
|
|
|
|
sphero.Name = "sphero"
|
|
|
|
sphero.Interval = "0.5s"
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
sphero.SetRGB(uint8(255), uint8(0), uint8(0))
|
|
|
|
}
|
|
|
|
|
2013-11-25 08:24:32 +08:00
|
|
|
master.Robots = append(master.Robots, gobot.Robot{
|
2013-11-25 06:56:13 +08:00
|
|
|
Name: name,
|
|
|
|
Connections: []interface{}{spheroAdaptor},
|
|
|
|
Devices: []interface{}{sphero},
|
|
|
|
Work: work,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2013-11-25 08:24:32 +08:00
|
|
|
master.Robots = append(master.Robots, gobot.Robot{
|
2013-11-25 06:56:13 +08:00
|
|
|
Work: func() {
|
2013-11-25 08:24:32 +08:00
|
|
|
sphero := master.FindRobot("Sphero-BPO")
|
2013-11-25 06:56:13 +08:00
|
|
|
gobot.Every("1s", func() {
|
|
|
|
gobot.Call(sphero.GetDevice("sphero").Driver, "SetRGB", uint8(gobot.Rand(255)), uint8(gobot.Rand(255)), uint8(gobot.Rand(255)))
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2013-11-25 08:24:32 +08:00
|
|
|
master.Start()
|
2013-11-24 01:15:44 +08:00
|
|
|
}
|