gobot.io/x/gobot/v2@v2.1.0/examples/chip_button_led.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 "gobot.io/x/gobot/v2" 11 "gobot.io/x/gobot/v2/drivers/gpio" 12 "gobot.io/x/gobot/v2/platforms/chip" 13 ) 14 15 func main() { 16 chipAdaptor := chip.NewAdaptor() 17 button := gpio.NewButtonDriver(chipAdaptor, "XIO-P6") 18 led := gpio.NewLedDriver(chipAdaptor, "XIO-P7") 19 20 work := func() { 21 button.On(gpio.ButtonPush, func(data interface{}) { 22 led.On() 23 }) 24 25 button.On(gpio.ButtonRelease, func(data interface{}) { 26 led.Off() 27 }) 28 } 29 30 robot := gobot.NewRobot("buttonBot", 31 []gobot.Connection{chipAdaptor}, 32 []gobot.Device{button, led}, 33 work, 34 ) 35 36 robot.Start() 37 }