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

46 lines
1003 B
Go
Raw Normal View History

2013-11-23 09:15:44 -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 09:15:44 -08:00
)
func main() {
2013-11-24 16:24:32 -08:00
master := gobot.GobotMaster()
2013-11-24 14:56:13 -08:00
spheros := map[string]string{
2013-12-03 10:43:22 -08:00
"Sphero-BPO": "/dev/rfcomm0",
2013-11-24 14:56:13 -08:00
}
for name, port := range spheros {
spheroAdaptor := new(sphero.Adaptor)
2013-11-24 14:56:13 -08:00
spheroAdaptor.Name = "sphero"
spheroAdaptor.Port = port
sphero := sphero.NewSphero(spheroAdaptor)
2013-11-24 14:56:13 -08:00
sphero.Name = "sphero"
sphero.Interval = "0.5s"
work := func() {
sphero.SetRGB(uint8(255), uint8(0), uint8(0))
}
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},
Devices: []gobot.Device{sphero},
2013-11-24 14:56:13 -08:00
Work: work,
})
}
2014-04-16 15:54:39 -07:00
master.Robots = append(master.Robots, &gobot.Robot{
2013-11-24 14:56:13 -08:00
Work: func() {
gobot.Every("1s", func() {
gobot.Call(master.FindRobot("Sphero-BPO").GetDevice("sphero").Driver, "SetRGB", uint8(gobot.Rand(255)), uint8(gobot.Rand(255)), uint8(gobot.Rand(255)))
2013-11-24 14:56:13 -08:00
})
},
})
2013-11-24 16:24:32 -08:00
master.Start()
2013-11-23 09:15:44 -08:00
}