gobot.io/x/gobot@v1.16.0/examples/firmata_makey_button.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 /* 6 How to run 7 Pass serial port to use as the first param: 8 9 go run examples/firmata_makey_button.go /dev/ttyACM0 10 */ 11 12 package main 13 14 import ( 15 "os" 16 17 "gobot.io/x/gobot" 18 "gobot.io/x/gobot/drivers/gpio" 19 "gobot.io/x/gobot/platforms/firmata" 20 ) 21 22 func main() { 23 firmataAdaptor := firmata.NewAdaptor(os.Args[1]) 24 button := gpio.NewMakeyButtonDriver(firmataAdaptor, "2") 25 led := gpio.NewLedDriver(firmataAdaptor, "13") 26 27 work := func() { 28 button.On(gpio.ButtonPush, func(data interface{}) { 29 led.On() 30 }) 31 32 button.On(gpio.ButtonRelease, func(data interface{}) { 33 led.Off() 34 }) 35 } 36 37 robot := gobot.NewRobot("makeyBot", 38 []gobot.Connection{firmataAdaptor}, 39 []gobot.Device{button, led}, 40 work, 41 ) 42 43 robot.Start() 44 }