当前位置:网站首页>树莓派 轻触开关 按键使用
树莓派 轻触开关 按键使用
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
边栏推荐
- [蓝桥杯2017初赛]包子凑数
- Nanny level problem setting tutorial
- Solve the problem of installing failed building wheel for pilot
- 牛客Novice月赛40
- Rhcsa certification exam exercise (configured on the first host)
- nodejs 详解
- SQL时间注入
- Integration test practice (1) theoretical basis
- 使用LinkedHashMap实现一个LRU算法的缓存
- How to set up voice recognition on the computer with shortcut keys
猜你喜欢
STM32型号与Contex m对应关系
分布式节点免密登录
{one week summary} take you into the ocean of JS knowledge
AcWing 1298. Solution to Cao Chong's pig raising problem
[Blue Bridge Cup 2017 preliminary] grid division
Vs2019 use wizard to generate an MFC Application
快来走进JVM吧
4. Install and deploy spark (spark on Yan mode)
UDS learning notes on fault codes (0x19 and 0x14 services)
MySQL与c语言连接(vs2019版)
随机推荐
Integration test practice (1) theoretical basis
[NPUCTF2020]ReadlezPHP
JS array + array method reconstruction
Machine learning notes week02 convolutional neural network
[AGC009D]Uninity
QT creator uses Valgrind code analysis tool
Small L's test paper
How to set up voice recognition on the computer with shortcut keys
[NPUCTF2020]ReadlezPHP
AcWing 1298. Solution to Cao Chong's pig raising problem
[蓝桥杯2021初赛] 砝码称重
Solution of deleting path variable by mistake
Vs2019 first MFC Application
double转int精度丢失问题
Mysql的索引实现之B树和B+树
[Blue Bridge Cup 2017 preliminary] grid division
常用正则表达式整理
[Bluebridge cup 2021 preliminary] weight weighing
Come and walk into the JVM
Heating data in data lake?