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