hybridgroup.gobot/examples/beaglebone_button.go

34 lines
717 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.NewButtonDriver(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("buttonBot",
[]gobot.Connection{beagleboneAdaptor},
[]gobot.Device{button},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}