树莓派点亮LED灯

简介

复制代码
使用GPIO Zero library 的 Python库实现点亮LED灯。

接线

树莓派引脚参考图如下:

LED正极 接GPIO17

LED负极 接GND

权限

将你的用户加到gpio组中, 否则无法控制GPIO

sudo usermod -a -G gpio

代码

python 复制代码
from gpiozero import LED
from time import sleep

led = LED(17)

while True:
    led.on()
    sleep(1)
    led.off()
    sleep(1)

参考

Raspberry Pi hardware - GPIO and the 40-pin header
GPIO in Python - LED示例

相关推荐
进阶的鱼3 分钟前
一文助你了解Langchain
python·langchain·agent
收菜福星4 分钟前
智能体来了:从 Python 开发者视角深度剖析与实践
python
佑白雪乐10 分钟前
<Python第1集>
开发语言·python
liu****12 分钟前
git工具
git·python·算法·机器学习·计算机基础
rgeshfgreh23 分钟前
2025年Python安装全指南
python
数据大魔方28 分钟前
【期货量化进阶】期货Tick数据分析与应用:高频数据入门(TqSdk完整教程)
python·算法·数据挖掘·数据分析·github·程序员创富·期货程序化
爱吃羊的老虎30 分钟前
Streamlit:快速创建应用界面,无需了解 Web 开发
前端·python
只想要搞钱37 分钟前
python 学习记录--1(开发工具,链接数据库mysql)
python·学习
星浩AI38 分钟前
深入理解 LlamaIndex:RAG 框架核心概念与实践
人工智能·后端·python
python开发笔记38 分钟前
can(6) canopen python库使用
服务器·网络·python