hybridgroup.gobot/examples/ollie.go

39 lines
626 B
Go

//go:build example
// +build example
//
// Do not build by default.
package main
import (
"os"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/platforms/ble"
"gobot.io/x/gobot/v2/platforms/sphero/ollie"
)
func main() {
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
ollie := ollie.NewDriver(bleAdaptor)
work := func() {
gobot.Every(1*time.Second, func() {
r := uint8(gobot.Rand(255))
g := uint8(gobot.Rand(255))
b := uint8(gobot.Rand(255))
ollie.SetRGB(r, g, b)
})
}
robot := gobot.NewRobot("ollieBot",
[]gobot.Connection{bleAdaptor},
[]gobot.Device{ollie},
work,
)
robot.Start()
}