[英]Read a Flashing Led in Arduino
So it's a simple problem, I have several LEDs on a board where depending on their states it will trigger a command to fire a relay.所以这是一个简单的问题,我在一块板上有几个 LED,根据它们的状态,它会触发一个命令来触发继电器。 Where I am stuck is figuring out how to get the Arduino to see a blinking LED, I have tried to bypass it all together but the code got larger than we wanted so it was scrapped and I am starting all over.我被困的地方是弄清楚如何让 Arduino 看到闪烁的 LED,我试图一起绕过它,但代码变得比我们想要的要大,所以它被废弃了,我从头开始。 Any ideas would be most helpful.任何想法都会很有帮助。 Here is the basic code:这是基本代码:
int Relay = 2;
int Led = 7;
int Ball = 8;
void setup()
{
Serial.begin(115200);
pinMode(Relay, OUTPUT);
pinMode(Led, INPUT);
pinMode(Ball, OUTPUT);
}
void loop()
{
digitalWrite (Relay, HIGH);
delay (500);
digitalWrite (Relay, LOW);
delay(300);
digitalRead(Led);
if(Led == HIGH)
{
digitalWrite(Ball, HIGH);
}
if(Led == LOW)
{
digitalWrite(Ball, LOW);
}
}
digitalRead(Led)
throws away the value you are reading, and if (Led == LOW)
is comparing a pin number with a voltage level, which is meaningless. digitalRead(Led)
会丢弃您正在读取的值, if (Led == LOW)
正在将引脚号与电压电平进行比较,这是没有意义的。 You mean:你的意思是:
level = digitalRead(Led);
if (level == HIGH) {
... if (level == HIGH) {
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.