2014-06-28 12:05:17 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-07-10 17:21:21 -07:00
|
|
|
|
2014-06-28 12:05:17 -06:00
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/beaglebone"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/gpio"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
|
|
|
|
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
|
|
|
|
button := gpio.NewButtonDriver(beagleboneAdaptor, "button", "P8_9")
|
|
|
|
|
|
|
|
work := func() {
|
2016-09-01 12:17:43 +02:00
|
|
|
button.On(gpio.ButtonPush, func(data interface{}) {
|
2014-06-28 12:05:17 -06:00
|
|
|
fmt.Println("button pressed")
|
|
|
|
})
|
|
|
|
|
2016-09-01 12:17:43 +02:00
|
|
|
button.On(gpio.ButtonRelease, func(data interface{}) {
|
2014-06-28 12:05:17 -06:00
|
|
|
fmt.Println("button released")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-08 18:36:14 -07:00
|
|
|
robot := gobot.NewRobot("buttonBot",
|
|
|
|
[]gobot.Connection{beagleboneAdaptor},
|
|
|
|
[]gobot.Device{button},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
gbot.AddRobot(robot)
|
2014-06-28 12:05:17 -06:00
|
|
|
gbot.Start()
|
|
|
|
}
|