gobot.io/x/gobot@v1.16.0/examples/chip_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/chip" 13 ) 14 15 func main() { 16 chipAdaptor := chip.NewAdaptor() 17 button := gpio.NewButtonDriver(chipAdaptor, "XIO-P0") 18 19 work := func() { 20 button.On(gpio.ButtonPush, func(data interface{}) { 21 fmt.Println("button pressed") 22 }) 23 24 button.On(gpio.ButtonRelease, func(data interface{}) { 25 fmt.Println("button released") 26 }) 27 } 28 29 robot := gobot.NewRobot("buttonBot", 30 []gobot.Connection{chipAdaptor}, 31 []gobot.Device{button}, 32 work, 33 ) 34 35 robot.Start() 36 }