hybridgroup.gobot/examples/sphero_multiple.go

52 lines
1.0 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"github.com/hybridgroup/gobot"
2014-04-27 09:07:04 +08:00
"github.com/hybridgroup/gobot/sphero"
)
func main() {
2014-04-27 09:07:04 +08:00
master := gobot.NewMaster()
spheros := []string{
"/dev/rfcomm0",
"/dev/rfcomm1",
"/dev/rfcomm2",
"/dev/rfcomm3",
}
for s := range spheros {
2014-04-27 09:07:04 +08:00
spheroAdaptor := sphero.NewSpheroAdaptor()
spheroAdaptor.Name = "Sphero"
spheroAdaptor.Port = spheros[s]
2014-04-27 09:07:04 +08:00
sphero := sphero.NewSphero(spheroAdaptor)
sphero.Name = "Sphero" + spheros[s]
sphero.Interval = "0.5s"
work := func() {
sphero.Stop()
gobot.On(sphero.Events["Collision"], func(data interface{}) {
fmt.Println("Collision Detected!")
})
gobot.Every("1s", func() {
sphero.Roll(100, uint16(gobot.Rand(360)))
})
gobot.Every("3s", func() {
sphero.SetRGB(uint8(gobot.Rand(255)), uint8(gobot.Rand(255)), uint8(gobot.Rand(255)))
})
}
master.Robots = append(master.Robots, &gobot.Robot{
Connections: []gobot.Connection{spheroAdaptor},
Devices: []gobot.Device{sphero},
Work: work,
})
}
master.Start()
}