闪烁程序快速引导了一段时间,然后在 Arduino UNO 上缓慢引导
Program for Blinking led quickly for some time and then slowly on Arduino UNO
我是 Arduino 的新手,我希望我的 LED 在 1 秒内快速闪烁 5 次,然后在 4 秒内缓慢闪烁,我试过这样,
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
int n=1;
while (n<=5)
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
while (n<=10)
{
digitalWrite (13, HIGH);
delay (2000) ;
digitalWrite(13, LOW) ;
delay(2000) ;
}
但是它不起作用,请帮我修复它。谢谢
您的代码有无限循环。既然你只是从 1 数到 5 或 10,为什么不让它们 for
循环?
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
int n;
for (n = 1; n <= 5; n++)
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
for (n = 1; n <= 10; n++)
{
digitalWrite(13, HIGH);
delay(2000);
digitalWrite(13, LOW);
delay(2000);
}
}
您没有在 while 循环内更新 'n'
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
int n=1;
while(n++ <= 5)
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
while(n++ <= 10)
{
digitalWrite (13, HIGH);
delay (2000) ;
digitalWrite(13, LOW) ;
delay(2000) ;
}
}
这现在应该可以正常工作了。
我是 Arduino 的新手,我希望我的 LED 在 1 秒内快速闪烁 5 次,然后在 4 秒内缓慢闪烁,我试过这样,
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
int n=1;
while (n<=5)
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
while (n<=10)
{
digitalWrite (13, HIGH);
delay (2000) ;
digitalWrite(13, LOW) ;
delay(2000) ;
}
但是它不起作用,请帮我修复它。谢谢
您的代码有无限循环。既然你只是从 1 数到 5 或 10,为什么不让它们 for
循环?
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
int n;
for (n = 1; n <= 5; n++)
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
for (n = 1; n <= 10; n++)
{
digitalWrite(13, HIGH);
delay(2000);
digitalWrite(13, LOW);
delay(2000);
}
}
您没有在 while 循环内更新 'n'
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
int n=1;
while(n++ <= 5)
{
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
while(n++ <= 10)
{
digitalWrite (13, HIGH);
delay (2000) ;
digitalWrite(13, LOW) ;
delay(2000) ;
}
}
这现在应该可以正常工作了。