Total noob here. I'm programming many LEDs to perform multiple functions in a light show sort of way. I've got about 6 different functions working fine, but I want to repeat each function a number of times before moving to the next function. I found this code
int i;
int n;
// Code to get some value of "n"
for (i = 0; i < n; i++) {// Loop to do "something" n times
// Do "something"
}
but I started with a sketch that set everything up with "index", so I'm not sure how to incorporate the above type of coding, as index already takes up my "for" loop to move between LEDs. Here is a simplified example of what I'm working on
int ledPins[] = {3,5,6};
void setup()
{
int index;
for(index = 0; index <= 2; index++)
{
pinMode(ledPins[index],OUTPUT);
}
}
void loop()
{
FUNCTION1();
FUNCTION2();
FUNCTION3();
FUNCTION4();
void FUNCTION1()
{
int index;
int delayTime = 200;
for(index = 0; index <= 2; index++)
{
digitalWrite(ledPins[index], HIGH);
delay(delayTime);
digitalWrite(ledPins[index], LOW);
}
for (index = 2; index >= 0; index--) {
digitalWrite(ledPins[index], HIGH);
delay(delayTime);
digitalWrite(ledPins[index], LOW);
}
}
void FUNCTION2()
{
int index;
int delayTime = 100;
for(index = 0; index <= 2; index++)
{
digitalWrite(ledPins[index], HIGH);
delay(delayTime);
}
for(index = 2; index >= 0; index--)
{
digitalWrite(ledPins[index], LOW);
delay(delayTime);
}
}
Is there another way to do what I want without using index, so I can use my "for" loop to determine the number of times the function repeats?
Secondary question...... How can I run 2 functions simultaneously with Function 1 controlling one group of outputs and Function 2 controlling a different group of outputs?
Sorry if this is a stupid question, but I'm stuck. Thanks in advance.