gobot.io/x/gobot/v2@v2.1.0/examples/edison_grove_touch.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  	"fmt"
    11  
    12  	"gobot.io/x/gobot/v2"
    13  	"gobot.io/x/gobot/v2/drivers/gpio"
    14  	"gobot.io/x/gobot/v2/platforms/intel-iot/edison"
    15  )
    16  
    17  func main() {
    18  	e := edison.NewAdaptor()
    19  	touch := gpio.NewGroveTouchDriver(e, "2")
    20  
    21  	work := func() {
    22  		touch.On(gpio.ButtonPush, func(data interface{}) {
    23  			fmt.Println("On!")
    24  		})
    25  
    26  		touch.On(gpio.ButtonRelease, func(data interface{}) {
    27  			fmt.Println("Off!")
    28  		})
    29  
    30  	}
    31  
    32  	robot := gobot.NewRobot("blinkBot",
    33  		[]gobot.Connection{e},
    34  		[]gobot.Device{touch},
    35  		work,
    36  	)
    37  
    38  	robot.Start()
    39  }