gobot.io/x/gobot/v2@v2.1.0/examples/edison_grove_button.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 button := gpio.NewGroveButtonDriver(e, "2") 20 21 work := func() { 22 button.On(gpio.ButtonPush, func(data interface{}) { 23 fmt.Println("On!") 24 }) 25 26 button.On(gpio.ButtonRelease, func(data interface{}) { 27 fmt.Println("Off!") 28 }) 29 30 } 31 32 robot := gobot.NewRobot("bot", 33 []gobot.Connection{e}, 34 []gobot.Device{button}, 35 work, 36 ) 37 38 robot.Start() 39 }