使用一个开关控制4个LED,并获得开关打开的状态 [英] Control 4 LED s using one switch and get status of which switch is turn on

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

问题描述

如果有4个LED和一个开关。此开关控制所有4个LED。



1.开关按1次 - 第1个LED开启

2.开关按2次 - 第1个LED熄灭,第2个LED转这样就好了。



所以我想知道,现在开启LED的数量是多少(第一个LED,第二个LED,第三个LED或第四个LED)

任何人都可以帮助我吗?



我的尝试:



我可以用Arduino做到这一点。

If there is 4 LED s and one switch. This switch controls the all 4 LED s.

1. switch press 1 times - 1st LED turn on
2. switch press 2 times - 1st LED turn off and 2nd LED turn ON like wise it happen.

So I want to know, what is the number of Now Turn ON Led(1st LED, 2nd LED, 3rd LED or 4th LED)
Can anyone help me?

What I have tried:

can I do this with an Arduino.

推荐答案

你最好找一个献给Arduino的论坛。



但是,一般的想法是当你看到开关按下时启动倒数计时器。只要计时器运行,您只需计算按下和释放开关的次数。当计时器到期时,您将停止寻找开关按下并根据您计算的按下次数处理LED。回去寻找第一台开关机。
You'd be better off finding a forum dedicate to Arduino.

But, the general idea would be to start a countdown timer when you see a the switch presses. So long as the timer is running you just count the number of times the switch is pressed and released. When the timer expires you stop looking for switch presses and process your LED's depending on the number of presses you counted. Go back to looking for the first switch press.


是的,原则上你可以这样做。

假设你有正确地删除了开关 [ ^ ]然后您只需计算在预定的时间内(例如1秒)按下开关的次数,然后点亮相应的LED(并确保另一个)其中一些已关闭。)
Yes, in principle, you can do that.
Supposing you have correctly debounced the switch[^] then you have simply to count how many times the switch has been pressed in a prefixed amount of time (e.g. 1 second), then light ON the correspondent LED (and make sure the other ones are switched OFF).


这篇关于使用一个开关控制4个LED,并获得开关打开的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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