1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
hybridgroup.gobot/examples/sphero_api.go

41 lines
834 B
Go
Raw Normal View History

2013-11-23 10:36:08 -08:00
package main
import (
2013-12-03 00:48:20 -08:00
"github.com/hybridgroup/gobot"
2014-05-22 21:20:16 -07:00
"github.com/hybridgroup/gobot/api"
"github.com/hybridgroup/gobot/platforms/sphero"
2013-11-23 10:36:08 -08:00
)
func main() {
2014-07-08 18:36:14 -07:00
gbot := gobot.NewGobot()
api.NewAPI(gbot).Start()
2013-11-24 14:56:13 -08:00
spheros := map[string]string{
2013-12-30 13:56:16 -08:00
"Sphero-BPO": "/dev/rfcomm0",
2013-11-24 14:56:13 -08:00
}
for name, port := range spheros {
2014-05-22 21:20:16 -07:00
spheroAdaptor := sphero.NewSpheroAdaptor("sphero", port)
2013-11-24 14:56:13 -08:00
2014-05-22 21:20:16 -07:00
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor, "sphero")
2013-11-24 14:56:13 -08:00
work := func() {
2014-04-28 11:40:20 -07:00
spheroDriver.SetRGB(uint8(255), uint8(0), uint8(0))
2013-11-24 14:56:13 -08:00
}
2014-07-08 18:36:14 -07:00
robot := gobot.NewRobot(name,
[]gobot.Connection{spheroAdaptor},
[]gobot.Device{spheroDriver},
work,
)
robot.AddCommand("turn_blue", func(params map[string]interface{}) interface{} {
spheroDriver.SetRGB(uint8(0), uint8(0), uint8(255))
return nil
})
2014-05-22 21:20:16 -07:00
2014-07-08 18:36:14 -07:00
gbot.AddRobot(robot)
2013-11-24 14:56:13 -08:00
}
2014-07-08 18:36:14 -07:00
gbot.Start()
2013-11-23 10:36:08 -08:00
}