使用golang对荔枝派等开发板的gpio控制
1、相关库介绍
通过修改/sys/class/gpio下面的相关文件实现的库:github.com/brian-armstrong/gpio
2、相关功能示例
2.1、对gpio口进行输出操作
1、以输出模式打开引脚
package main
import "github.com/brian-armstrong/gpio"
pin := gpio.NewOutput(65, true)
2、设置电平状态
package main
import "github.com/brian-armstrong/gpio"
pin := gpio.NewOutput(65, true)
err := pin.Low()
if err != nil{
panic(err)
}
3、设置引脚为高电平状态
package main
import "github.com/brian-armstrong/gpio"
pin := gpio.NewOutput(65, true)
err := pin.High()
if err != nil{
panic(err)
}
2.2、对gpio进行读取操作
1、以读取模式打开引脚
package main
import "github.com/brian-armstrong/gpio"
pin := gpio.NewInput(65)
2、读取引脚值
package main
import "github.com/brian-armstrong/gpio"
pin := gpio.NewInput(65)
read, err := pin.Read()
if err != nil {
panic(err)
}
|