gobot.io/x/gobot@v1.16.0/examples/ollie_roll.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  		ollie.SetRGB(255, 0, 255)
    22  		gobot.Every(3*time.Second, func() {
    23  			ollie.Roll(40, uint16(gobot.Rand(360)))
    24  		})
    25  	}
    26  
    27  	robot := gobot.NewRobot("ollieBot",
    28  		[]gobot.Connection{bleAdaptor},
    29  		[]gobot.Device{ollie},
    30  		work,
    31  	)
    32  
    33  	robot.Start()
    34  }