2014-06-29 02:05:17 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-07-11 08:21:21 +08:00
|
|
|
|
2014-06-29 02:05:17 +08:00
|
|
|
"github.com/hybridgroup/gobot"
|
2016-10-03 22:58:43 +08:00
|
|
|
"github.com/hybridgroup/gobot/drivers/gpio"
|
2014-06-29 02:05:17 +08:00
|
|
|
"github.com/hybridgroup/gobot/platforms/beaglebone"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
|
2016-10-03 22:58:43 +08:00
|
|
|
beagleboneAdaptor := beaglebone.NewAdaptor()
|
|
|
|
button := gpio.NewMakeyButtonDriver(beagleboneAdaptor, "P8_9")
|
2014-06-29 02:05:17 +08:00
|
|
|
|
|
|
|
work := func() {
|
2016-09-01 18:17:43 +08:00
|
|
|
button.On(gpio.ButtonPush, func(data interface{}) {
|
2014-06-29 02:05:17 +08:00
|
|
|
fmt.Println("button pressed")
|
|
|
|
})
|
|
|
|
|
2016-09-01 18:17:43 +08:00
|
|
|
button.On(gpio.ButtonRelease, 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()
|
|
|
|
}
|