当前位置:网站首页>树莓派 轻触开关 按键使用
树莓派 轻触开关 按键使用
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
边栏推荐
- Those commonly used tool classes and methods in hutool
- MySQL与c语言连接(vs2019版)
- 第4阶段 Mysql数据库
- express框架详解
- AI benchmark V5 ranking
- Integration test practice (1) theoretical basis
- error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_ s instead
- DICOM: Overview
- [蓝桥杯2017初赛]包子凑数
- 搞笑漫画:程序员的逻辑
猜你喜欢

wangeditor富文本引用、表格使用问题

Request object and response object analysis

vs2019 使用向导生成一个MFC应用程序

MongoDB
![[Blue Bridge Cup 2017 preliminary] grid division](/img/e9/e49556d0867840148a60ff4906f78e.png)
[Blue Bridge Cup 2017 preliminary] grid division

Kept VRRP script, preemptive delay, VIP unicast details

Face recognition_ recognition

Cookie setting three-day secret free login (run tutorial)

MySQL主从复制的原理以及实现

{一周总结}带你走进js知识的海洋
随机推荐
4. Install and deploy spark (spark on Yan mode)
Base de données Advanced Learning Notes - - SQL statements
Case analysis of data inconsistency caused by Pt OSC table change
Wangeditor rich text component - copy available
2020网鼎杯_朱雀组_Web_nmap
【Flink】CDH/CDP Flink on Yarn 日志配置
Machine learning notes week02 convolutional neural network
天梯赛练习集题解LV1(all)
Valentine's Day flirting with girls to force a small way, one can learn
ES6 Promise 对象
Codeforces Round #771 (Div. 2)
Pytoch Foundation
[NPUCTF2020]ReadlezPHP
L2-004 is this a binary search tree? (25 points)
Cookie setting three-day secret free login (run tutorial)
MySQL与c语言连接(vs2019版)
4、安装部署Spark(Spark on Yarn模式)
JS array + array method reconstruction
Why can't STM32 download the program
[CDH] modify the default port 7180 of cloudera manager in cdh/cdp environment