2014-06-29 02:05:17 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"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.NewMakeyButtonDriver(beagleboneAdaptor, "button", "P8_9")
|
|
|
|
|
|
|
|
work := func() {
|
2014-07-09 09:36:14 +08:00
|
|
|
gobot.On(button.Event("push"), func(data interface{}) {
|
2014-06-29 02:05:17 +08:00
|
|
|
fmt.Println("button pressed")
|
|
|
|
})
|
|
|
|
|
2014-07-09 09:36:14 +08:00
|
|
|
gobot.On(button.Event("release"), func(data interface{}) {
|
2014-06-29 02:05:17 +08:00
|
|
|
fmt.Println("button released")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-09 09:36:14 +08:00
|
|
|
robot := gobot.NewRobot("makeyBot",
|
|
|
|
[]gobot.Connection{beagleboneAdaptor},
|
|
|
|
[]gobot.Device{button},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
2014-06-29 02:05:17 +08:00
|
|
|
gbot.Start()
|
|
|
|
}
|