gobot.io/x/gobot@v1.16.0/examples/leap_motion_hands.go (about)

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"gobot.io/x/gobot"
    11  	"gobot.io/x/gobot/platforms/leap"
    12  )
    13  
    14  func main() {
    15  	leapMotionAdaptor := leap.NewAdaptor("127.0.0.1:6437")
    16  	l := leap.NewDriver(leapMotionAdaptor)
    17  
    18  	work := func() {
    19  		l.On(leap.HandEvent, func(data interface{}) {
    20  			printHand(data.(leap.Hand))
    21  		})
    22  	}
    23  
    24  	robot := gobot.NewRobot("leapBot",
    25  		[]gobot.Connection{leapMotionAdaptor},
    26  		[]gobot.Device{l},
    27  		work,
    28  	)
    29  
    30  	robot.Start()
    31  }
    32  
    33  func printHand(hand leap.Hand) {
    34  	fmt.Println("Hand", hand)
    35  }