gobot.io/x/gobot/v2@v2.1.0/examples/ollie_boost.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  	"os"
    11  	"time"
    12  
    13  	"gobot.io/x/gobot/v2"
    14  	"gobot.io/x/gobot/v2/platforms/ble"
    15  	"gobot.io/x/gobot/v2/platforms/sphero/ollie"
    16  )
    17  
    18  func main() {
    19  	bleAdaptor := ble.NewClientAdaptor(os.Args[1])
    20  	ollieBot := ollie.NewDriver(bleAdaptor)
    21  
    22  	work := func() {
    23  		head := 90
    24  		ollieBot.SetRGB(255, 0, 0)
    25  		ollieBot.Boost(true)
    26  		gobot.Every(1*time.Second, func() {
    27  			ollieBot.Roll(0, uint16(head))
    28  			time.Sleep(1 * time.Second)
    29  			head += 90
    30  			head = head % 360
    31  		})
    32  	}
    33  
    34  	robot := gobot.NewRobot("ollieBot",
    35  		[]gobot.Connection{bleAdaptor},
    36  		[]gobot.Device{ollieBot},
    37  		work,
    38  	)
    39  
    40  	robot.Start()
    41  }