gobot.io/x/gobot@v1.16.0/examples/ollie_boost.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  	ollieBot := ollie.NewDriver(bleAdaptor)
    19  
    20  	work := func() {
    21  		head := 90
    22  		ollieBot.SetRGB(255, 0, 0)
    23  		ollieBot.Boost(true)
    24  		gobot.Every(1*time.Second, func() {
    25  			ollieBot.Roll(0, uint16(head))
    26  			time.Sleep(1 * time.Second)
    27  			head += 90
    28  			head = head % 360
    29  		})
    30  	}
    31  
    32  	robot := gobot.NewRobot("ollieBot",
    33  		[]gobot.Connection{bleAdaptor},
    34  		[]gobot.Device{ollieBot},
    35  		work,
    36  	)
    37  
    38  	robot.Start()
    39  }