hybridgroup.gobot/examples/beaglebone_button.go

35 lines
677 B
Go

package main
import (
"fmt"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/beaglebone"
)
func main() {
gbot := gobot.NewMaster()
beagleboneAdaptor := beaglebone.NewAdaptor()
button := gpio.NewButtonDriver(beagleboneAdaptor, "P8_9")
work := func() {
button.On(gpio.ButtonPush, func(data interface{}) {
fmt.Println("button pressed")
})
button.On(gpio.ButtonRelease, func(data interface{}) {
fmt.Println("button released")
})
}
robot := gobot.NewRobot("buttonBot",
[]gobot.Connection{beagleboneAdaptor},
[]gobot.Device{button},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}