1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
deadprogram 1013863f7c sprkplus: add new platform for Sphero SPRK+
Signed-off-by: deadprogram <ron@hybridgroup.com>
2017-10-31 15:15:55 +01:00

46 lines
757 B
Go

// +build example
//
// Do not build by default.
/*
How to run
Pass the Bluetooth address or name as the first param:
go run examples/sprkplus.go SK-1234
NOTE: sudo is required to use BLE in Linux
*/
package main
import (
"os"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/ble"
"gobot.io/x/gobot/platforms/sphero/sprkplus"
)
func main() {
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
sprk := sprkplus.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))
sprk.SetRGB(r, g, b)
})
}
robot := gobot.NewRobot("sprkBot",
[]gobot.Connection{bleAdaptor},
[]gobot.Device{sprk},
work,
)
robot.Start()
}