1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
hybridgroup.gobot/examples/sphero_multiple.go
2014-04-28 11:40:20 -07:00

52 lines
1.1 KiB
Go

package main
import (
"fmt"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/sphero"
)
func main() {
master := gobot.NewMaster()
spheros := []string{
"/dev/rfcomm0",
"/dev/rfcomm1",
"/dev/rfcomm2",
"/dev/rfcomm3",
}
for s := range spheros {
spheroAdaptor := sphero.NewSpheroAdaptor()
spheroAdaptor.Name = "Sphero"
spheroAdaptor.Port = spheros[s]
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
spheroDriver.Name = "Sphero" + spheros[s]
spheroDriver.Interval = "0.5s"
work := func() {
spheroDriver.Stop()
gobot.On(spheroDriver.Events["Collision"], func(data interface{}) {
fmt.Println("Collision Detected!")
})
gobot.Every("1s", func() {
spheroDriver.Roll(100, uint16(gobot.Rand(360)))
})
gobot.Every("3s", func() {
spheroDriver.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{spheroDriver},
Work: work,
})
}
master.Start()
}