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