2016-07-10 01:52:48 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2016-07-11 02:08:34 +08:00
|
|
|
"time"
|
2016-09-01 19:32:40 +08:00
|
|
|
|
2016-07-10 01:52:48 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/ble"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-16 02:02:54 +08:00
|
|
|
gbot := gobot.NewMaster()
|
2016-07-10 01:52:48 +08:00
|
|
|
|
2016-10-03 22:58:43 +08:00
|
|
|
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
|
|
|
|
ollie := ble.NewSpheroOllieDriver(bleAdaptor)
|
2016-07-10 01:52:48 +08:00
|
|
|
|
|
|
|
work := func() {
|
2016-07-11 02:08:34 +08: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-10 01:52:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("ollieBot",
|
|
|
|
[]gobot.Connection{bleAdaptor},
|
|
|
|
[]gobot.Device{ollie},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
|
|
|
}
|