title: 树莓派3B开发Go语言案例-双色LED
tags: 树莓派,go,golang,3B,3B+,led
该案例实现红绿两色LED灯交叉闪烁,针脚及接线图如下
引脚图实现代码
package main
import (
"log"
"time"
"periph.io/x/periph/conn/gpio"
"periph.io/x/periph/host"
"periph.io/x/periph/host/rpi"
)
func main() {
// 加载所有驱动
if _, err := host.Init(); err != nil {
log.Fatal(err)
}
ticker := time.NewTicker(500 * time.Millisecond)
// 针脚11, = bcm283x.GPIO17
redLed := rpi.P1_11
// 针脚12, = bcm283x.GPIO18
greenLed := rpi.P1_12
for l := gpio.Low; ; l = !l {
if err := redLed.Out(l); err != nil {
log.Fatal(err)
}
if err := greenLed.Out(!l); err != nil {
log.Fatal(err)
}
<-ticker.C
}
}
网友评论