2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2017-02-24 00:07:02 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-03-13 23:01:39 +08:00
|
|
|
"fmt"
|
2017-02-24 00:07:02 +08:00
|
|
|
|
2017-03-13 23:01:39 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/drivers/gpio"
|
|
|
|
"gobot.io/x/gobot/platforms/chip"
|
2017-02-24 00:07:02 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-03-13 23:01:39 +08:00
|
|
|
dragonAdaptor := chip.NewAdaptor()
|
|
|
|
button := gpio.NewButtonDriver(dragonAdaptor, "GPIO_A")
|
|
|
|
|
|
|
|
work := func() {
|
2017-04-04 19:38:51 +08:00
|
|
|
button.On(gpio.ButtonPush, func(data interface{}) {
|
2017-03-13 23:01:39 +08:00
|
|
|
fmt.Println("button pressed")
|
|
|
|
})
|
|
|
|
|
2017-04-04 19:38:51 +08:00
|
|
|
button.On(gpio.ButtonRelease, func(data interface{}) {
|
2017-03-13 23:01:39 +08:00
|
|
|
fmt.Println("button released")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("buttonBot",
|
2017-04-04 19:38:51 +08:00
|
|
|
[]gobot.Connection{dragonAdaptor},
|
2017-03-13 23:01:39 +08:00
|
|
|
[]gobot.Device{button},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|