1
0
mirror of https://github.com/kidoman/embd synced 2024-11-10 19:48:53 +01:00
embd/samples/gpiointerrupt.go
SjB 0fa1d1b61c gpio: adding interrupt
this is inspired by Dave Cheney's gpio library and his work on EPOLL
2014-09-02 23:12:55 -04:00

43 lines
613 B
Go

// +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)
}