forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bb8.go
45 lines (35 loc) · 737 Bytes
/
bb8.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// +build example
//
// Do not build by default.
/*
How to run
Pass the Bluetooth address or name as the first param:
go run examples/bb8.go BB-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/bb8"
)
func main() {
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
bb8 := bb8.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))
bb8.SetRGB(r, g, b)
})
}
robot := gobot.NewRobot("bbBot",
[]gobot.Connection{bleAdaptor},
[]gobot.Device{bb8},
work,
)
robot.Start()
}