1 Star 0 Fork 0

人月神话 / gpio

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
watcher.go 1021 Bytes
一键复制 编辑 原始数据 按行查看 历史
人月神话 提交于 2021-03-20 11:47 . modify package name
// Copyright © 2017 Kent Gibson <warthog618@gmail.com>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"gitee.com/lhjw9810/gpio"
)
// Watches GPIO 4 (J8 7) and reports when it changes state.
func main() {
err := gpio.Open()
if err != nil {
panic(err)
}
defer gpio.Close()
pin := gpio.NewPin(gpio.J8p7)
pin.Input()
pin.PullUp()
// capture exit signals to ensure resources are released on exit.
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(quit)
err = pin.Watch(gpio.EdgeBoth, func(pin *gpio.Pin) {
fmt.Printf("Pin 4 is %v", pin.Read())
})
if err != nil {
panic(err)
}
defer pin.Unwatch()
// In a real application the main thread would do something useful here.
// But we'll just run for a minute then exit.
fmt.Println("Watching Pin 4...")
select {
case <-time.After(time.Minute):
case <-quit:
}
}
1
https://gitee.com/lhjw9810/gpio.git
git@gitee.com:lhjw9810/gpio.git
lhjw9810
gpio
gpio
v1.0.1

搜索帮助