2023-05-20 14:25:21 +02:00
|
|
|
//go:build example
|
2017-03-13 11:01:39 -04:00
|
|
|
// +build example
|
2023-05-20 14:25:21 +02:00
|
|
|
|
2017-03-13 11:01:39 -04:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2024-11-01 12:54:20 +01:00
|
|
|
//nolint:gosec // ok here
|
2016-07-09 11:52:48 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2016-07-10 12:08:34 -06:00
|
|
|
"time"
|
2016-09-01 13:32:40 +02:00
|
|
|
|
2023-05-20 14:25:21 +02:00
|
|
|
"gobot.io/x/gobot/v2"
|
2024-02-04 18:50:43 +01:00
|
|
|
"gobot.io/x/gobot/v2/drivers/ble/sphero"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/bleclient"
|
2016-07-09 11:52:48 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-02-04 18:50:43 +01:00
|
|
|
bleAdaptor := bleclient.NewAdaptor(os.Args[1])
|
|
|
|
ollie := sphero.NewOllieDriver(bleAdaptor)
|
2016-07-09 11:52:48 -06:00
|
|
|
|
|
|
|
work := func() {
|
2016-07-10 12:08:34 -06:00
|
|
|
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)
|
|
|
|
})
|
2016-07-09 11:52:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("ollieBot",
|
|
|
|
[]gobot.Connection{bleAdaptor},
|
|
|
|
[]gobot.Device{ollie},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2024-02-11 15:34:50 +01:00
|
|
|
if err := robot.Start(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2016-07-09 11:52:48 -06:00
|
|
|
}
|