我々はloop
機能を「アンロール」場合は、我々が得る:
// Loops is 1 on the first call.
digitalWrite(13, LOW);
Loops = Loops + 1;
// Loops is now 2
if (Loops < 3)
{
// So, we enter here...
digitalWrite(13, HIGH);
delay(2000);
}
else
{
// but not here
digitalWrite(13, LOW);
exit(0);
}
// Next call:
// Turn off the light.
digitalWrite(13, LOW);
Loops = Loops + 1;
// Loops is now 3
if (Loops < 3)
{
// So we don't enter here
digitalWrite(13, HIGH);
delay(2000);
}
else
{
// but we enter here
digitalWrite(13, LOW);
// Which exits
exit(0);
}
だから、あなたはそれをオフにし、一度のLEDをオンにします終了します。
ループカウンターを調整すると、LEDが消えてすぐに再びオンになります。これは長い間点灯しているように見えます。あなたはおそらく、各ループにオン/オフサイクル全体をやりたい
- このような何か:
int LedPin = 13;
int Loops = 0;
void setup() {
pinMode(LedPin, OUTPUT);
digitalWrite(LedPin, LOW);
}
void loop() {
Loops = Loops + 1;
if (Loops <= 3)
{
digitalWrite(LedPin, HIGH);
delay(2000);
digitalWrite(LedPin, LOW);
delay(2000);
}
else
{
exit(0);
}
}
は4だ – user3528438