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