当前位置:网站首页>红外传感器控制开关
红外传感器控制开关
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
边栏推荐
- Migrating your native/mobile application to Unified Plan/WebRTC 1.0 API
- [recommendation for new books in 2021] professional azure SQL managed database administration
- Android interview Online Economic encyclopedia [constantly updating...]
- oracle表的约束详解
- ProcessBuilder工具类
- MySQL notes 1_ database
- 取消远程依赖,用本地依赖
- 组件化学习(3)ARouter中的Path和Group注解
- iTOP4412内核反复重启
- MySQL笔记3_约束_主键约束
猜你喜欢

从0开始封装一套项目的网络请求框架

杂七杂八的学习

【2021年新书推荐】Practical Node-RED Programming

Binder mechanism principle

AVD Pixel_2_API_24 is already running.If that is not the case, delete the files at C:\Users\admi

【2021年新书推荐】Red Hat Certified Engineer (RHCE) Study Guide

【2021年新书推荐】Professional Azure SQL Managed Database Administration

Bottom navigation bar based on bottomnavigationview

Project, how to package

Personal blog website construction
随机推荐
iTOP4412 HDMI显示(4.0.3_r1)
oracle通过触发器和序列来定义自增主键,并且设置定时任务每秒钟插入一条数据到目标表
What did you do during the internship
JS 比较2个数组中不同的元素
iTOP4412 LCD背光驱动(PWM)
oracle表的约束详解
【2021年新书推荐】Enterprise Application Development with C# 9 and .NET 5
【2021年新书推荐】Professional Azure SQL Managed Database Administration
iTOP4412 FramebufferNativeWindow(4.0.3_r1)
[2021 book recommendation] practical node red programming
oracle用delete删除数据所需时间测试
【2021年新书推荐】Practical Node-RED Programming
组件化学习(3)ARouter中的Path和Group注解
[SM8150][Pixel4]LCD驱动
C#新大陆物联网云平台的连接(简易理解版)
Itop4412 cannot display boot animation (4.0.3_r1)
个人学习相关
MySQL notes 3_ Restraint_ Primary key constraint
Personal blog website construction
MySQL5. 7 insert Chinese data and report an error: ` incorrect string value: '\ xb8 \ XDF \ AE \ xf9 \ X80 at row 1`