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