当前位置:网站首页>红外传感器控制开关
红外传感器控制开关
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
边栏推荐
猜你喜欢
Project, how to package
ViewPager2实现画廊效果执行notifyDataSetChanged后PageTransformer显示异常 界面变形问题
统一任务分发调度执行框架
组件化学习(2)Arouter原理学习
【2021年新书推荐】Red Hat Certified Engineer (RHCE) Study Guide
Cause: dx.jar is missing
窗口分析函数LAST_VALUE,FIRST_VALUE,lag,lead
this.getOptions is not a function
[recommendation of new books in 2021] enterprise application development with C 9 and NET 5
Viewpager2 realizes Gallery effect. After notifydatasetchanged, pagetransformer displays abnormal interface deformation
随机推荐
谷歌AdMob广告学习
[recommendation for new books in 2021] professional azure SQL managed database administration
Migrating your native/mobile application to Unified Plan/WebRTC 1.0 API
Encapsulate a set of project network request framework from 0
Cause: dx. jar is missing
Android interview Online Economic encyclopedia [constantly updating...]
MySQL notes 3_ Restraint_ Primary key constraint
Cancel remote dependency and use local dependency
[exynos4412] [itop4412] [android-k] add product options
Viewpager2 realizes Gallery effect. After notifydatasetchanged, pagetransformer displays abnormal interface deformation
[recommendation of new books in 2021] practical IOT hacking
MySQL笔记5_操作数据
第三篇:docker安装mysql容器(自定义端口)
Itop4412 kernel restarts repeatedly
Record WebView shows another empty pit
组件化学习(2)Arouter原理学习
【2021年新书推荐】Enterprise Application Development with C# 9 and .NET 5
ViewPager2实现画廊效果执行notifyDataSetChanged后PageTransformer显示异常 界面变形问题
Itop4412 surfaceflinger (4.4.4_r1)
[2021 book recommendation] practical node red programming