gobot.io/x/gobot/v2@v2.1.0/examples/bb8.go (about) 1 //go:build example 2 // +build example 3 4 // 5 // Do not build by default. 6 7 /* 8 How to run 9 Pass the Bluetooth address or name as the first param: 10 11 go run examples/bb8.go BB-1234 12 13 NOTE: sudo is required to use BLE in Linux 14 */ 15 16 package main 17 18 import ( 19 "os" 20 "time" 21 22 "gobot.io/x/gobot/v2" 23 "gobot.io/x/gobot/v2/platforms/ble" 24 "gobot.io/x/gobot/v2/platforms/sphero/bb8" 25 ) 26 27 func main() { 28 bleAdaptor := ble.NewClientAdaptor(os.Args[1]) 29 bb8 := bb8.NewDriver(bleAdaptor) 30 31 work := func() { 32 gobot.Every(1*time.Second, func() { 33 r := uint8(gobot.Rand(255)) 34 g := uint8(gobot.Rand(255)) 35 b := uint8(gobot.Rand(255)) 36 bb8.SetRGB(r, g, b) 37 }) 38 } 39 40 robot := gobot.NewRobot("bbBot", 41 []gobot.Connection{bleAdaptor}, 42 []gobot.Device{bb8}, 43 work, 44 ) 45 46 robot.Start() 47 }