Go Down

Topic: Random thread hijack (Read 150 times) previous topic - next topic

kvk

int ledPins[] = {2,3,4,5,6,7,8,9};

void setup()
{
 int index;
 for(index = 0; index <= 7; index++)
 {
   pinMode(ledPins[index],OUTPUT);
 }
}

void loop()
{
 
  oneOnAtATime();
 //pingPong();
 //marquee();
randomLED();
}
void randomLED()


{
 int index;
 int delayTime;

index = random(8);    delayTime = 100;

 digitalWrite(ledPins[index], HIGH);  
 delay(delayTime);              
 digitalWrite(ledPins[index], LOW);  

index = random(8);    delayTime = 100;

 digitalWrite(ledPins[index], HIGH);  
 delay(delayTime);              
 digitalWrite(ledPins[index], LOW);

index = random(8);    delayTime = 100;

 digitalWrite(ledPins[index], HIGH);  
 delay(delayTime);              
 digitalWrite(ledPins[index], LOW);  

index = random(8);    delayTime = 100;

 digitalWrite(ledPins[index], HIGH);  
 delay(delayTime);              
 digitalWrite(ledPins[index], LOW);  

index = random(8);    delayTime = 100;

 digitalWrite(ledPins[index], HIGH);  
 delay(delayTime);              
 digitalWrite(ledPins[index], LOW);  

index = random(8);    delayTime = 100;

 digitalWrite(ledPins[index], HIGH);  
 delay(delayTime);              
 digitalWrite(ledPins[index], LOW);  

index = random(8);    delayTime = 100;

 digitalWrite(ledPins[index], HIGH);  
 delay(delayTime);              
 digitalWrite(ledPins[index], LOW);  

index = random(8);    delayTime = 100;

 digitalWrite(ledPins[index], HIGH);  
 delay(delayTime);              
 digitalWrite(ledPins[index], LOW);  

index = random(8);    delayTime = 100;

 digitalWrite(ledPins[index], HIGH);  
 delay(delayTime);              
 digitalWrite(ledPins[index], LOW);  

index = random(8);    delayTime = 100;

 digitalWrite(ledPins[index], HIGH);  
 delay(delayTime);              
 digitalWrite(ledPins[index], LOW);  

delay(delayTime = 500);

}


     
void oneOnAtATime()
{
 int index;
 int delayTime = 200;                    

 for(index = 0; index <= 7; index++)
 {
   digitalWrite(ledPins[index], HIGH);
   delay(delayTime);          
   digitalWrite(ledPins[index], LOW);
 }

 delay(delayTime = 1000);
}


Подскажите пожалуйста, как в подпрограмме randomLED() из 10 раз

index = random(8);    delayTime = 100;

 digitalWrite(ledPins[index], HIGH);  
 delay(delayTime);              
 digitalWrite(ledPins[index], LOW);  

написать данную подпрограмму минимизируя с ее колличеством повтора .


UKHeliBob

And now again please in [­code][­/code] tags to get rid of the smileys
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

sterretje

This is what google translate makes from the question
Quote
write this subroutine minimizing with its number of repetitions
So, do you see a pattern? If so, time to use a function that can take a pin number. If you don't know how to use a function, google for c function tutorial
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

TomGeorge

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

dave-in-nj

read the sticky posts on every forum.
how to use this forum.
read  #6. Make a meaningful subject line
then come back and and make a meaningful subject line.


then read #7. If you are posting code or error messages, use "code" tags
Then come back and add 'code' tags


on your post, bottom right is where you click to modify your post




Go Up