hybridgroup.gobot/examples/sphero_api.go

47 lines
1.0 KiB
Go
Raw Normal View History

2013-11-24 02:36:08 +08:00
package main
import (
2013-12-03 14:46:25 +08:00
. "github.com/hybridgroup/gobot"
. "github.com/hybridgroup/gobot-sphero"
2013-11-24 02:36:08 +08:00
)
2013-11-28 12:05:45 +08:00
var Master *gobot.Master = gobot.GobotMaster()
func TurnBlue(params map[string]interface{}) bool {
2013-11-28 12:35:32 +08:00
sphero := Master.FindRobotDevice(params["robotname"].(string), "sphero")
2013-11-28 12:05:45 +08:00
gobot.Call(sphero.Driver, "SetRGB", uint8(0), uint8(0), uint8(255))
return true
}
2013-11-24 02:36:08 +08:00
func main() {
2013-11-28 12:05:45 +08:00
gobot.Api(Master)
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-28 12:05:45 +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-28 12:05:45 +08:00
Commands: map[string]interface{}{"TurnBlue": TurnBlue},
2013-11-25 06:56:13 +08:00
})
}
2013-11-28 12:05:45 +08:00
Master.Start()
2013-11-24 02:36:08 +08:00
}