2017-03-13 11:01:39 -04:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2017-07-12 18:08:46 -06:00
|
|
|
/*
|
|
|
|
How to run
|
|
|
|
Pass serial port to use as the first param:
|
|
|
|
|
|
|
|
go run examples/firmata_button.go /dev/ttyACM0
|
|
|
|
*/
|
|
|
|
|
2014-04-26 03:11:51 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-07-12 18:08:46 -06:00
|
|
|
"os"
|
|
|
|
|
2016-12-08 13:24:03 +01:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/drivers/gpio"
|
|
|
|
"gobot.io/x/gobot/platforms/firmata"
|
2014-04-26 03:11:51 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-07-12 18:08:46 -06:00
|
|
|
firmataAdaptor := firmata.NewAdaptor(os.Args[1])
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2017-02-08 15:33:52 +01:00
|
|
|
button := gpio.NewButtonDriver(firmataAdaptor, "2")
|
|
|
|
led := gpio.NewLedDriver(firmataAdaptor, "3")
|
2014-04-26 03:11:51 -07:00
|
|
|
|
|
|
|
work := func() {
|
2016-09-01 12:17:43 +02:00
|
|
|
button.On(gpio.ButtonPush, func(data interface{}) {
|
2014-04-26 03:11:51 -07:00
|
|
|
led.On()
|
|
|
|
})
|
2016-09-01 12:17:43 +02:00
|
|
|
button.On(gpio.ButtonRelease, func(data interface{}) {
|
2014-04-26 03:11:51 -07:00
|
|
|
led.Off()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-08 18:36:14 -07:00
|
|
|
robot := gobot.NewRobot("buttonBot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{button, led},
|
|
|
|
work,
|
2014-04-29 13:20:32 -07:00
|
|
|
)
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2016-10-18 21:08:25 +02:00
|
|
|
robot.Start()
|
2014-04-26 03:11:51 -07:00
|
|
|
}
|