35 lines
649 B
Go
35 lines
649 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
"github.com/hybridgroup/gobot/drivers/gpio"
|
|
"github.com/hybridgroup/gobot/platforms/chip"
|
|
)
|
|
|
|
func main() {
|
|
gbot := gobot.NewMaster()
|
|
|
|
chipAdaptor := chip.NewAdaptor()
|
|
button := gpio.NewButtonDriver(chipAdaptor, "XIO-P0")
|
|
|
|
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{chipAdaptor},
|
|
[]gobot.Device{button},
|
|
work,
|
|
)
|
|
gbot.AddRobot(robot)
|
|
gbot.Start()
|
|
}
|