2016-03-30 15 views
-4

Arduino programında 3 kez yanıp sönen döngüyü üç kez çalıştırmak istiyorum. Döngü 3 kez nasıl çalıştırılır ve döngüde dönüş ifadesinden nasıl kullanılır? bir kez led 1 saniye sürüyor ve sonra gidiyor.Arduino programında 3 kez yanıp sönme açılamıyor

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 var – user3528438

cevap

0

, elde ederiz:: Bölüm 5'e Kontrol Yapıları göz at

// 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); 
} 

Yani bir kez LED açmak, ardından kapatın ve çıkış.
Döngü sayacını ayarlarsanız, LED'i kapatır ve hemen tekrar açarsınız, bu daha uzun bir süre açık kalacak gibi görünür.

Muhtemelen her döngü/kapalı döngüsü bir bütün yapmak istiyorum - böyle bir şey:

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

"nasıl c bir döngü yazmak için" google lütfen zamanlar. – 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 

}