-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
bleclient_ollie_multiple.go
62 lines (48 loc) · 1.09 KB
/
bleclient_ollie_multiple.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//go:build example
// +build example
//
// Do not build by default.
/*
To run this example, pass the BLE address or BLE name as first param:
go run examples/ollie_multiple.go 2B-1234 2B-5678
NOTE: sudo is required to use BLE in Linux
*/
//nolint:gosec // ok here
package main
import (
"os"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/api"
"gobot.io/x/gobot/v2/drivers/ble/sphero"
"gobot.io/x/gobot/v2/platforms/bleclient"
)
func NewSwarmBot(port string) *gobot.Robot {
bleAdaptor := bleclient.NewAdaptor(port)
ollieDriver := sphero.NewOllieDriver(bleAdaptor)
work := func() {
gobot.Every(1*time.Second, func() {
ollieDriver.SetRGB(uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
)
})
}
robot := gobot.NewRobot("ollie "+port,
[]gobot.Connection{bleAdaptor},
[]gobot.Device{ollieDriver},
work,
)
return robot
}
func main() {
manager := gobot.NewManager()
api.NewAPI(manager).Start()
for _, port := range os.Args[1:] {
bot := NewSwarmBot(port)
manager.AddRobot(bot)
}
if err := manager.Start(); err != nil {
panic(err)
}
}