我目前正在尝试为Arduino Uno编写代码。我有四(4)排六(6)个LED灯,我正试图让它们在一个柜台上自己运行。下面是我的代码,但我遇到了一个问题,灯打开了,但不会熄灭。我目前正在使用TinkerCad尝试进行故障排除。虽然代码处理了所有四(4)行的灯光,但我只在void循环()中编写了一行。任何建议都是有帮助的!
// Test for board
int LEDblue = 13;
int LEDblueON = 1000;
int LEDblueOFF = 1000;
int LEDgreen = 12;
int LEDgreenON = 2000;
int LEDgreenOFF = 2000;
int LEDyellow = 11;
int LEDyellowON = 4000;
int LEDyellowOFF = 4000;
int LEDred = 10;
int LEDredON = 8000;
int LEDredOFF = 8000;
int CounterBlue = 0;
int CounterGreen = 0;
int CounterYellow = 0;
int CounterRed = 0;
void setup()
{
pinMode (LEDblue, OUTPUT);
pinMode (LEDgreen, OUTPUT);
pinMode (LEDyellow, OUTPUT);
pinMode (LEDred, OUTPUT);
}
void loop()
{
if (CounterBlue <LEDblueON);
{
digitalWrite(LEDblue, HIGH);
}
if (CounterBlue=LEDblueON+LEDblueOFF);
{
digitalWrite(LEDblue, LOW);
}
if(CounterBlue>LEDblueON+LEDblueOFF);
{
(CounterBlue= 0);
}
delay(1);
}发布于 2017-07-21 01:22:16
主要的问题是,在if语句的条件之后,例如
if (CounterBlue <LEDblueON);
{
digitalWrite(LEDblue, HIGH);
}括号前有一个;。如果您将其更改为
if (CounterBlue <LEDblueON)
{
digitalWrite(LEDblue, HIGH);
}它应该工作得很好。
https://stackoverflow.com/questions/45173470
复制相似问题