gobot.io/x/gobot@v1.16.0/examples/ollie.go (about)

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"os"
     9  	"time"
    10  
    11  	"gobot.io/x/gobot"
    12  	"gobot.io/x/gobot/platforms/ble"
    13  	"gobot.io/x/gobot/platforms/sphero/ollie"
    14  )
    15  
    16  func main() {
    17  	bleAdaptor := ble.NewClientAdaptor(os.Args[1])
    18  	ollie := ollie.NewDriver(bleAdaptor)
    19  
    20  	work := func() {
    21  		gobot.Every(1*time.Second, func() {
    22  			r := uint8(gobot.Rand(255))
    23  			g := uint8(gobot.Rand(255))
    24  			b := uint8(gobot.Rand(255))
    25  			ollie.SetRGB(r, g, b)
    26  		})
    27  	}
    28  
    29  	robot := gobot.NewRobot("ollieBot",
    30  		[]gobot.Connection{bleAdaptor},
    31  		[]gobot.Device{ollie},
    32  		work,
    33  	)
    34  
    35  	robot.Start()
    36  }