当前位置:网站首页>树莓派 轻触开关 按键使用
树莓派 轻触开关 按键使用
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
边栏推荐
- 误删Path变量解决
- JS array + array method reconstruction
- mysql实现读写分离
- Word typesetting (subtotal)
- Antlr4 uses keywords as identifiers
- Password free login of distributed nodes
- Mtcnn face detection
- 2020 WANGDING cup_ Rosefinch formation_ Web_ nmap
- Valentine's Day flirting with girls to force a small way, one can learn
- Pytoch Foundation
猜你喜欢
How to configure flymcu (STM32 serial port download software) is shown in super detail
Mtcnn face detection
Request object and response object analysis
[Blue Bridge Cup 2017 preliminary] grid division
Stage 4 MySQL database
Vs2019 use wizard to generate an MFC Application
保姆级出题教程
{one week summary} take you into the ocean of JS knowledge
Reading BMP file with C language
Learn winpwn (2) -- GS protection from scratch
随机推荐
机器学习笔记-Week02-卷积神经网络
Are you monitored by the company for sending resumes and logging in to job search websites? Deeply convinced that the product of "behavior awareness system ba" has not been retrieved on the official w
Niuke novice monthly race 40
AcWing 242. A simple integer problem (tree array + difference)
L2-001 emergency rescue (25 points)
nodejs连接Mysql
Connexion sans mot de passe du noeud distribué
分布式节点免密登录
2019 Tencent summer intern formal written examination
[Blue Bridge Cup 2017 preliminary] grid division
AcWing 179. Factorial decomposition problem solution
MTCNN人脸检测
Detailed explanation of express framework
[CDH] cdh5.16 configuring the setting of yarn task centralized allocation does not take effect
Wangeditor rich text reference and table usage
【flink】flink学习
Codeforces Round #753 (Div. 3)
Using LinkedHashMap to realize the caching of an LRU algorithm
天梯赛练习集题解LV1(all)
[Bluebridge cup 2021 preliminary] weight weighing