2014-04-26 18:11:51 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/hybridgroup/gobot"
|
2014-04-27 09:07:04 +08:00
|
|
|
"github.com/hybridgroup/gobot/sphero"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-04-27 09:07:04 +08:00
|
|
|
master := gobot.NewMaster()
|
2014-04-26 18:11:51 +08:00
|
|
|
|
|
|
|
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()
|
2014-04-26 18:11:51 +08:00
|
|
|
spheroAdaptor.Name = "Sphero"
|
|
|
|
spheroAdaptor.Port = spheros[s]
|
|
|
|
|
2014-04-27 09:07:04 +08:00
|
|
|
sphero := sphero.NewSphero(spheroAdaptor)
|
2014-04-26 18:11:51 +08:00
|
|
|
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()
|
|
|
|
}
|