当前位置:网站首页>树莓派GPIO引脚控制红绿灯与轰鸣器
树莓派GPIO引脚控制红绿灯与轰鸣器
2022-07-02 03:42:00 【loong_XL】
参考:
https://blog.csdn.net/weixin_44415639/article/details/114600919
https://blog.csdn.net/chenbo163/article/details/78716269
https://blog.51cto.com/u_11643026/4291142
这里文章用的编程引脚是物理引擎代号BOARD
1、GPIO控制包安装
参考:https://blog.csdn.net/weixin_42078116/article/details/119329032
gpio -v 版本2.52才行,2.50查看gpio readall输出报错
需要单独安装解决:
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio readall
2、代码控制红绿灯和有源轰鸣器
1)红绿灯
GND引脚用来接地,(GND引脚插在9,红色对应插在11;黄色插在13,绿色插在15)
2)有源轰鸣器
3个引脚,GND引脚用来接地,VCC引脚用来接3.3V的电源,I/O引脚用来GPIO编程控制蜂鸣器;(GND引脚插在39,这里VCC对应插在17;I/O引脚插在37)
有源轰鸣器,因为是低电平触发响,初始时设置为高电平GPIO.HIGH就可以不响
#!/usr/bin/python
#coding:utf-8
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
# 进行引脚的初始化,因为是低电平触发,初始时设置为高电平
GPIO.setup(37, GPIO.OUT,initial=GPIO.HIGH) #轰鸣器
GPIO.setup(11,GPIO.OUT) #红
GPIO.setup(13,GPIO.OUT) #黄
GPIO.setup(15,GPIO.OUT) #绿
def blink():
#通过交替输出高低电频来是LED灯闪烁
#红灯亮10s
GPIO.output(11,GPIO.HIGH)
time.sleep(10)
GPIO.output(11,GPIO.LOW)
time.sleep(0.5)
#黄灯亮3s
GPIO.output(13,GPIO.HIGH)
time.sleep(3.0)
GPIO.output(13,GPIO.LOW)
time.sleep(0.5)
# 绿灯亮10s
GPIO.output(15,GPIO.HIGH)
time.sleep(10)
GPIO.output(15,GPIO.LOW)
time.sleep(0.5)
# 黄灯亮3s
GPIO.output(13,GPIO.HIGH)
time.sleep(3.0)
GPIO.output(13,GPIO.LOW)
GPIO.output(37,GPIO.LOW)
time.sleep(3.0)
GPIO.output(37,GPIO.HIGH)
#主程序
try:
#循环执行
while True:
blink()
except KeyboardInterrupt:
pass
GPIO.cleanup()

树莓派 红绿灯 GPIO
边栏推荐
- u本位合约爆仓清算解决方案建议
- MySQL index, transaction and storage engine
- [designmode] builder model
- Object oriented thinking
- SQL Yiwen get window function
- The second game of the 11th provincial single chip microcomputer competition of the Blue Bridge Cup
- Kotlin basic learning 14
- 数据库文件逻辑结构形式指的是什么
- This article describes the step-by-step process of starting the NFT platform project
- ThreadLocal详解
猜你喜欢

Vite: configure IP access

【IBDFE】基于IBDFE的频域均衡matlab仿真

Basic operations of MySQL database (based on tables)

How to do medium and long-term stocks, and what are the medium and long-term stock trading skills?

Haute performance et faible puissance Cortex - A53 Core Board | i.mx8m mini

The 11th Blue Bridge Cup single chip microcomputer provincial competition

Basic syntax of unity script (6) - specific folder

Review materials of project management PMP high frequency examination sites (8-1)

The fourth provincial competition of Bluebridge cup single chip microcomputer

Homework in Chapter 3 of slam course of dark blue vision -- derivative application of T6 common functions
随机推荐
[database]jdbc
【IBDFE】基于IBDFE的频域均衡matlab仿真
ImageAI安装
Basic syntax of unity script (7) - member variables and instantiation
Gradle foundation | customize the plug-in and upload it to jitpack
Didi open source Delta: AI developers can easily train natural language models
SQL Yiwen get window function
Knowing things by learning | self supervised learning helps improve the effect of content risk control
High performance and low power cortex-a53 core board | i.mx8m Mini
Imageai installation
The 7th Blue Bridge Cup single chip microcomputer provincial competition
VS2010 plug-in nuget
接口调试工具模拟Post上传文件——ApiPost
近段时间天气暴热,所以采集北上广深去年天气数据,制作可视化图看下
Jetpack之LiveData扩展MediatorLiveData
The fourth provincial competition of Bluebridge cup single chip microcomputer
Vite: scaffold assembly
5G时代全面到来,浅谈移动通信的前世今生
In wechat applet, the externally introduced JS is used in xwml for judgment and calculation
The second game of the 12th provincial single chip microcomputer competition of the Blue Bridge Cup