控制LED系列使用开关 [英] Control LED series using switch

查看:65
本文介绍了控制LED系列使用开关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用开关控制4个led。我按下开关一次,第一个LED开启。过了一段时间,另一个领导者一个接一个地打开/关闭。没有提到延迟。



我怎么想获得led的状态。现在是开启了吗?



我尝试了什么:



不使用传感器,怎么做?

I want to control 4 led s using switch. I pressed switch one time first LED is turn on. after some time another led s are turn on/ off one by one. the delay is not mentioned.

how ever I want to get status of led. which is the turn on led now?

What I have tried:

without using sensor, how to do that?

推荐答案

只需使用变量跟踪程序中的状态:

每当LED由程序打开或关闭相应的状态变量。



上述要求在启动程序时知道状态(例如,关闭所有LED) 。



作为替代方案,使用 digitalRead()读取LED端口的引脚状态。这也适用于定义为输出的端口。
Just track the status within your program using a variable:
Whenever a LED is switched on or off by your program set the status variable accordingly.

The above requires the state to be known when starting the program (e.g. by switching all LEDs off).

As an alternative read the pin state of the LED ports using digitalRead(). This will work also for ports defined as output.


这篇关于控制LED系列使用开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆