当前位置:网站首页>红外传感器控制开关
红外传感器控制开关
2022-04-23 06:10:00 【林-金鹏】
一、效果预览
红外传感器控制开关
二、实现过程
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
# 采用实际的物理管脚给GPIO口
GPIO.setmode(GPIO.BOARD)
# 设置管脚为输入模式,上拉至高电平(3.3V)
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# LED管脚设置
# 设置Pin模式为输出模式
GPIO.setup(12, GPIO.OUT)
# 设置Pin管脚为低电平(0V)关闭LED
GPIO.output(12, GPIO.LOW)
# 设置频率为2KHz
Led = GPIO.PWM(12, 2000)
Led.start(0)
# 无限循环
def loop():
while True:
if (0 == GPIO.input(11)):
# 出现屏障,亮灯
Led.ChangeDutyCycle(100.0)
else:
# 移除屏障,熄灯
Led.start(0)
# 程序入口
if __name__ == '__main__':
try:
# 无限循环
loop()
# 当按下Ctrl+C时,将执行destroy()子程序
except KeyboardInterrupt:
# 调用释放资源
GPIO.cleanup()

版权声明
本文为[林-金鹏]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_46105038/article/details/120787633
边栏推荐
- npm ERR code 500解决
- 谷歌AdMob广告学习
- Three methods to realize the rotation of ImageView with its own center as the origin
- Using stack to realize queue out and in
- 【2021年新书推荐】Enterprise Application Development with C# 9 and .NET 5
- Bottomsheetdialogfragment conflicts with listview recyclerview Scrollview sliding
- MySQL notes 1_ database
- Cause: dx. jar is missing
- this. getOptions is not a function
- Ffmpeg common commands
猜你喜欢

C connection of new world Internet of things cloud platform (simple understanding version)

谷歌AdMob广告学习
![[recommendation for new books in 2021] professional azure SQL managed database administration](/img/f1/b38cce1dc328a5b534011169909127.png)
[recommendation for new books in 2021] professional azure SQL managed database administration

Itop4412 HDMI display (4.0.3_r1)

ffmpeg常用命令

记录webView显示空白的又一坑

开篇:双指针仪表盘的识别

SSL/TLS应用示例

个人博客网站搭建

Project, how to package
随机推荐
【2021年新书推荐】Artificial Intelligence for IoT Cookbook
Android暴露组件——被忽略的组件安全
Itop4412 kernel restarts repeatedly
oracle生成毫秒级时间戳
WebView displays a blank due to a certificate problem
iTOP4412 HDMI显示(4.4.4_r1)
[recommendation of new books in 2021] enterprise application development with C 9 and NET 5
开篇:双指针仪表盘的识别
Using stack to realize queue out and in
DCMTK(DCM4CHE)与DICOOGLE协同工作
oracle中生成32位uuid
Recyclerview 批量更新View:notifyItemRangeInserted、notifyItemRangeRemoved、notifyItemRangeChanged
【2021年新书推荐】Learn WinUI 3.0
MySQL5. 7 insert Chinese data and report an error: ` incorrect string value: '\ xb8 \ XDF \ AE \ xf9 \ X80 at row 1`
去掉状态栏
Explore how @ modelandview can forward data and pages through the source code
MySQL notes 1_ database
iTOP4412 SurfaceFlinger(4.4.4_r1)
通过rownum来进行区间查询
窗口分析函数LAST_VALUE,FIRST_VALUE,lag,lead