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() {
|
2016-10-16 02:02:54 +08:00
|
|
|
gbot := gobot.NewMaster()
|
2014-06-29 02:05:17 +08:00
|
|
|
|
2016-10-03 22:58:43 +08:00
|
|
|
beagleboneAdaptor := beaglebone.NewAdaptor()
|
|
|
|
button := gpio.NewButtonDriver(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("buttonBot",
|
|
|
|
[]gobot.Connection{beagleboneAdaptor},
|
|
|
|
[]gobot.Device{button},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
gbot.AddRobot(robot)
|
2014-06-29 02:05:17 +08:00
|
|
|
gbot.Start()
|
|
|
|
}
|