package main
import (
"os"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/api"
"gobot.io/x/gobot/platforms/ble"
"gobot.io/x/gobot/platforms/sphero/ollie"
)
func NewSwarmBot(port string) *gobot.Robot {
bleAdaptor := ble.NewClientAdaptor(port)
ollieDriver := ollie.NewDriver(bleAdaptor)
work := func() {
gobot.Every(1*time.Second, func() {
ollieDriver.SetRGB(uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
)
})
}
robot := gobot.NewRobot("ollie "+port,
[]gobot.Connection{bleAdaptor},
[]gobot.Device{ollieDriver},
work,
)
return robot
}
func main() {
master := gobot.NewMaster()
api.NewAPI(master).Start()
for _, port := range os.Args[1:] {
bot := NewSwarmBot(port)
master.AddRobot(bot)
}
master.Start()
}