树莓派3B开发Go语言案例-1.双色LED

栏目: 软件资讯 · 发布时间: 7年前

内容简介:title: 树莓派3B开发Go语言案例-双色LEDtags: 树莓派,go,golang,3B,3B+,led该案例实现红绿两色LED灯交叉闪烁,针脚及接线图如下

title: 树莓派3B开发 Go 语言案例-双色LED

tags: 树莓派,go,golang,3B,3B+,led

该案例实现红绿两色LED灯交叉闪烁,针脚及接线图如下

树莓派3B开发Go语言案例-1.双色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.GPIO18
    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
    }
}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

Beginning ARKit for iPhone and iPad

Beginning ARKit for iPhone and iPad

Wallace Wang / Apress / 2018-11-5 / USD 39.99

Explore how to use ARKit to create iOS apps and learn the basics of augmented reality while diving into ARKit specific topics. This book reveals how augmented reality allows you to view the screen on ......一起来看看 《Beginning ARKit for iPhone and iPad》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具