gobot.io/x/gobot@v1.16.0/examples/edison_button.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 package main 6 7 import ( 8 "gobot.io/x/gobot" 9 "gobot.io/x/gobot/drivers/gpio" 10 "gobot.io/x/gobot/platforms/intel-iot/edison" 11 ) 12 13 func main() { 14 e := edison.NewAdaptor() 15 16 button := gpio.NewButtonDriver(e, "5") 17 led := gpio.NewLedDriver(e, "13") 18 19 work := func() { 20 button.On(gpio.ButtonPush, func(data interface{}) { 21 led.On() 22 }) 23 button.On(gpio.ButtonRelease, func(data interface{}) { 24 led.Off() 25 }) 26 } 27 28 robot := gobot.NewRobot("buttonBot", 29 []gobot.Connection{e}, 30 []gobot.Device{led, button}, 31 work, 32 ) 33 34 robot.Start() 35 }