mirror of
https://github.com/kidoman/embd
synced 2025-07-03 03:47:33 +02:00
gpio: adding interrupt
this is inspired by Dave Cheney's gpio library and his work on EPOLL
This commit is contained in:
parent
6ad940090c
commit
0fa1d1b61c
4 changed files with 216 additions and 0 deletions
42
samples/gpiointerrupt.go
Normal file
42
samples/gpiointerrupt.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/kidoman/embd"
|
||||
|
||||
_ "github.com/kidoman/embd/host/all"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if err := embd.InitGPIO(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer embd.CloseGPIO()
|
||||
|
||||
btn, err := embd.NewDigitalPin(10)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer btn.Close()
|
||||
|
||||
if err := btn.SetDirection(embd.In); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
btn.ActiveLow(false)
|
||||
|
||||
quit := make(chan interface{})
|
||||
err = btn.Watch(embd.EdgeFalling, func(btn embd.DigitalPin) {
|
||||
quit <- btn
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Button %v was pressed.\n", <-quit)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue