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