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

47 lines
1.1 KiB
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"
"github.com/hybridgroup/gobot/sphero"
2013-11-23 10:36:08 -08:00
)
2014-04-28 11:40:20 -07:00
var Master *gobot.Master = gobot.NewMaster()
2013-11-27 20:05:45 -08:00
func TurnBlue(params map[string]interface{}) bool {
2014-04-28 11:40:20 -07:00
spheroDriver := Master.FindRobotDevice(params["robotname"].(string), "sphero")
2013-11-27 20:05:45 -08:00
gobot.Call(sphero.Driver, "SetRGB", uint8(0), uint8(0), uint8(255))
return true
}
2013-11-23 10:36:08 -08:00
func main() {
2013-11-27 20:05:45 -08:00
gobot.Api(Master)
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-04-28 11:40:20 -07:00
spheroAdaptor := sphero.NewSpheroAdaptor()
2013-11-24 14:56:13 -08:00
spheroAdaptor.Name = "sphero"
spheroAdaptor.Port = port
2014-04-28 11:40:20 -07:00
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
spheroDriver.Name = "sphero"
spheroDriver.Interval = "0.5s"
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-04-16 15:54:39 -07:00
Master.Robots = append(Master.Robots, &gobot.Robot{
2013-11-24 14:56:13 -08:00
Name: name,
2013-12-30 13:56:16 -08:00
Connections: []gobot.Connection{spheroAdaptor},
2014-04-28 11:40:20 -07:00
Devices: []gobot.Device{spheroDriver},
2013-11-24 14:56:13 -08:00
Work: work,
2013-11-27 20:05:45 -08:00
Commands: map[string]interface{}{"TurnBlue": TurnBlue},
2013-11-24 14:56:13 -08:00
})
}
2013-11-27 20:05:45 -08:00
Master.Start()
2013-11-23 10:36:08 -08:00
}