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