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