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