2016-03-30 20 views
-4

Arduinoプログラムで3回ループを3回点滅させて点滅させたいと思います。ループを3回実行してループを終了するにはどうすればよいですか?いったん導かれて1秒間続いてから降りる。Arduinoプログラムでledを3回点滅させることができません

int LedPin = 13; 
int Loops = 1; 
void setup() { 

    pinMode(LedPin, OUTPUT); 
} 

void loop() { 
digitalWrite(13, LOW); 
Loops = Loops + 1; 
    if (Loops < 3) 

    { 
     digitalWrite(13, HIGH); 
     delay(2000); 
    } 

else { 
    digitalWrite(13, LOW);  
    exit(0); 
    } 
} 
+4

は4だ – user3528438

答えて

0

arduinoループは永遠にループします。

https://www.arduino.cc/en/Reference/Loop

あなたはそのループの実行を停止する場合は、スリープモードでのArduinoを置くことができます:

http://playground.arduino.cc/Learning/ArduinoSleepCode

私はまた、あなたがどのようにフロー制御の動作(で徹底的に見てお勧めします可能であればステートマシン)。第5章制御構造を見てみましょう:

https://www.arduino.cc/en/Tutorial/BuiltInExamples

0

我々は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); 
    } 
} 
0
void setup() { 
    // initialize digital pin 13 as an output. 


    for (int i=0; i < 4 ; i++) 
    { 
    pinMode(13, OUTPUT); 
    digitalWrite(13, HIGH); 
    delay(1000); 
    digitalWrite(13, LOW); // turn the LED off by making the voltage LOW 
     delay(1000);  

    } 

} 

// the loop function runs over and over again forever 
void loop() { 

} 
+0

「Cでループの書き方」のためのgoogleしてください回。 – user3528438

-1
int LedPin = 13; 

void setup() { 
pinMode(LedPin, OUTPUT); 
function() ;  //call this function whatever you want 
} 

void function() 
{ 
digitalWrite(LedPin, HIGH); 
delay(1000)  //add the desired delay 
digitalWrite(LedPin, LOW); 
delay(1000)  //add the desired delay 
digitalWrite(LedPin, HIGH); 
delay(1000)  //add the desired delay 
digitalWrite(LedPin, LOW); 
delay(1000)  //add the desired delay 
digitalWrite(LedPin, HIGH); 
delay(1000)  //add the desired delay 
digitalWrite(LedPin, LOW); 
delay(1000)  //add the desired delay 

} 
関連する問題