gobot.io/x/gobot/v2@v2.1.0/examples/sphero_api.go (about) 1 //go:build example 2 // +build example 3 4 // 5 // Do not build by default. 6 7 package main 8 9 import ( 10 "gobot.io/x/gobot/v2" 11 "gobot.io/x/gobot/v2/api" 12 "gobot.io/x/gobot/v2/platforms/sphero" 13 ) 14 15 func main() { 16 master := gobot.NewMaster() 17 api.NewAPI(master).Start() 18 19 spheros := map[string]string{ 20 "Sphero-BPO": "/dev/rfcomm0", 21 } 22 23 for name, port := range spheros { 24 spheroAdaptor := sphero.NewAdaptor(port) 25 spheroDriver := sphero.NewSpheroDriver(spheroAdaptor) 26 27 work := func() { 28 spheroDriver.SetRGB(uint8(255), uint8(0), uint8(0)) 29 } 30 31 robot := gobot.NewRobot(name, 32 []gobot.Connection{spheroAdaptor}, 33 []gobot.Device{spheroDriver}, 34 work, 35 ) 36 robot.AddCommand("turn_blue", func(params map[string]interface{}) interface{} { 37 spheroDriver.SetRGB(uint8(0), uint8(0), uint8(255)) 38 return nil 39 }) 40 41 master.AddRobot(robot) 42 } 43 44 master.Start() 45 }