当前位置:网站首页>树莓派 轻触开关 按键使用
树莓派 轻触开关 按键使用
2022-07-06 09:16:00 【忘尘的世界】
问题咨询及项目源码下载请加群:
群名:IT项目交流群
群号:245022761
2、运用树莓派设计一个简单的按键控制LED灯点亮系统。通过树莓派控制器读取外部数字信号,使用三个按键分别控制三种颜色的 LED灯,当有按键按下时对应的LED灯会点亮,按键松开后对应的LED灯则熄灭。按下三个按键中的一个按键时,可以看到对应的一个LED灯会点亮;同时按下其中两个按键时,对应的两个LED灯会亮起;同时按下三个按键时则三个LED灯同时亮起。完成该控制系统的硬件连接线路设计,画出系统硬件原理框图及程序流程图,编写程序,系统联调通过并进行总结分析。
import RPi.GPIO import time yellow=0 red=5 green=6 button1=13 button2=19 button3=26 RPi.GPIO.setmode(RPi.GPIO.BCM) RPi.GPIO.setup(red,RPi.GPIO.OUT) RPi.GPIO.setup(green,RPi.GPIO.OUT) RPi.GPIO.setup(yellow,RPi.GPIO.OUT) RPi.GPIO.setup(button1, RPi.GPIO.IN, pull_up_down=RPi.GPIO.PUD_UP) RPi.GPIO.setup(button2, RPi.GPIO.IN, pull_up_down=RPi.GPIO.PUD_UP) RPi.GPIO.setup(button3, RPi.GPIO.IN, pull_up_down=RPi.GPIO.PUD_UP) try: RPi.GPIO.output(red,1) RPi.GPIO.output(green,1) RPi.GPIO.output(yellow,1) while True: time.sleep(0.06) if RPi.GPIO.input(button1) == 0: RPi.GPIO.output(red,1) else: RPi.GPIO.output(red,0) if RPi.GPIO.input(button2) == 0: RPi.GPIO.output(green,1) else: RPi.GPIO.output(green,0) if RPi.GPIO.input(button3) == 0: RPi.GPIO.output(yellow, 1) else: RPi.GPIO.output(yellow, 0) except KeyboardInterrupt: pass
边栏推荐
- Vs2019 first MFC Application
- AcWing 1294. Cherry Blossom explanation
- Connexion sans mot de passe du noeud distribué
- MTCNN人脸检测
- When using lambda to pass parameters in a loop, the parameters are always the same value
- Funny cartoon: Programmer's logic
- UDS learning notes on fault codes (0x19 and 0x14 services)
- Learning question 1:127.0.0.1 refused our visit
- 【yarn】CDP集群 Yarn配置capacity调度器批量分配
- Library function -- (continuous update)
猜你喜欢
![[Blue Bridge Cup 2017 preliminary] grid division](/img/e9/e49556d0867840148a60ff4906f78e.png)
[Blue Bridge Cup 2017 preliminary] grid division

分布式节点免密登录

{one week summary} take you into the ocean of JS knowledge

Mtcnn face detection

Machine learning -- census data analysis

Vs2019 first MFC Application

保姆级出题教程

error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_ s instead

分布式節點免密登錄

Word排版(小計)
随机推荐
[Bluebridge cup 2020 preliminary] horizontal segmentation
[mrctf2020] dolls
2020 WANGDING cup_ Rosefinch formation_ Web_ nmap
Word typesetting (subtotal)
【presto】presto 参数配置优化
Funny cartoon: Programmer's logic
Kept VRRP script, preemptive delay, VIP unicast details
【CDH】CDH5.16 配置 yarn 任务集中分配设置不生效问题
Detailed explanation of express framework
L2-006 tree traversal (25 points)
TypeScript
Learn winpwn (2) -- GS protection from scratch
MySQL主从复制的原理以及实现
AcWing 1294. Cherry Blossom explanation
L2-007 family real estate (25 points)
nodejs连接Mysql
jS数组+数组方法重构
分布式節點免密登錄
天梯赛练习集题解LV1(all)
[yarn] CDP cluster yarn configuration capacity scheduler batch allocation