hybridgroup.gobot/examples/beaglebone_makey_button.go

36 lines
723 B
Go
Raw Normal View History

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{}) {
fmt.Println("button pressed")
})
2014-07-09 09:36:14 +08:00
gobot.On(button.Event("release"), func(data interface{}) {
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)
gbot.Start()
}