-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathbeaglebone_button.go
More file actions
40 lines (31 loc) · 733 Bytes
/
Copy pathbeaglebone_button.go
File metadata and controls
40 lines (31 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//go:build example
// +build example
//
// Do not build by default.
package main
import (
"fmt"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/platforms/beagleboard/beaglebone"
)
func main() {
beagleboneAdaptor := beaglebone.NewAdaptor()
button := gpio.NewButtonDriver(beagleboneAdaptor, "P8_09")
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,
)
if err := robot.Start(); err != nil {
panic(err)
}
}