gobot.io/x/gobot/v2@v2.1.0/examples/bebop.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  	"time"
    11  
    12  	"gobot.io/x/gobot/v2"
    13  	"gobot.io/x/gobot/v2/platforms/parrot/bebop"
    14  )
    15  
    16  func main() {
    17  	bebopAdaptor := bebop.NewAdaptor()
    18  	drone := bebop.NewDriver(bebopAdaptor)
    19  
    20  	work := func() {
    21  		drone.On(bebop.Flying, func(data interface{}) {
    22  			gobot.After(10*time.Second, func() {
    23  				drone.Land()
    24  			})
    25  		})
    26  
    27  		drone.HullProtection(true)
    28  		drone.TakeOff()
    29  	}
    30  
    31  	robot := gobot.NewRobot("drone",
    32  		[]gobot.Connection{bebopAdaptor},
    33  		[]gobot.Device{drone},
    34  		work,
    35  	)
    36  
    37  	robot.Start()
    38  }