Please Help

I am new to programming and have a project of setting up an arduino to control 3 strands of leds. I have gotten them to loop so each strand will flash one at a time but once the last strand flashes I need all 3 of them to flashed together 3 to 4 times then start the cycle over. Below is the program I have so far can anyone please show me what to add to make this work correctly?



//Led setup

int timer = 100;

void setup() {
for (int strand1 = 1; strand1 < 4; strand1++) {
pinMode(strand1, OUTPUT);
}
}

void loop() {
for (int strand1 = 1; strand1 < 4; strand1++) {
digitalWrite(strand1, HIGH);
delay(timer);
digitalWrite(strand1, LOW);
To get them to all blink, use three loops:

1
2
3
4
5
6
7
8
9
10
11
for (int allBlink = 0; allBlink < 3; allBlink++) {
    for (int strand1 = 1; strand1 < 4; strand1++) {
        digitalWrite(strand1, HIGH);
    }

    delay(timer);

    for (int strand1 = 1; strand1 < 4; strand1++) {
        digitalWrite(strand1, LOW);
    }
}


By the way, when you post code, use the code tags. The show up as "<>" in the format box to the right of the text box.
Last edited on
This will make them blink strand by strand then all together? Thank you for your help and for the advice on posting. I am definately a newbie to this.
The outer loop will be the counter. The first inner loop will turn all the strands on. The second inner loop will turn all the strands off.

sorry. I did make a mistake. There should be another delay(timer); statement after the second inner loop. Otherwise the strands will be turned back on right away, and you will not notice them blinking off.

Cool thank you for all your help. The outer loop is what I had already came up with correct? It will look like this once it is all put together?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Led setup

 int timer = 100; 

void setup() {
 for (int strand1 = 1; strand1 < 4; strand1++) {
 pinMode(strand1, OUTPUT); 
}
 }

 void loop() {
 for (int strand1 = 1; strand1 < 4; strand1++) { 
digitalWrite(strand1, HIGH); 
delay(timer); 
digitalWrite(strand1, LOW);
    }
  delay(timer);

for (int allBlink = 0; allBlink < 3; allBlink++) {
    for (int strand1 = 1; strand1 < 4; strand1++) {
        digitalWrite(strand1, HIGH);
    }

    delay(timer);

    for (int strand1 = 1; strand1 < 4; strand1++) {
        digitalWrite(strand1, LOW);
    }
} 
What your originally came up with is not what I refer to as the outer loop. It was a function definition containing a single loop to blink each light independently. That was good.

My "outer loop" is the for (int allBlink = 0; allBlink < 3; allBlink++) loop that you put into your code. It contains 2 other loops, one to turn on each strand, and one to turn off each strand.

You added a delay(timer); statement after the "blink each strand" loop which means there will be a slight delay after the individual blinks and all the mass blinks. I'm guessing you added this because of my comment about not being able to see the lights blink, but you put it in the wrong place. (It's not wrong to put it there--it might even be what you want--but it won't help you see the lights blinking.)

My comment about the missing delay(timer); statement still holds. In your mass blink loop (my "outer loop"), you do not delay between turning all the strands off and turning them on again. There should be another delay(timer); statement between lines 28 and 29 so you can see the blinking.
Thank you for your help with this. I finally got evertyhing together and it works good. I am running the leds off a 4 channel relay board. I have one channel left. If I wanted to as this into the program but to make it flash seperate from the rest would the programming needed to be added in basically be the same as the instructions to make pin13 blink from the Arduino wedsite?
I am not familiar with the Arduino stuff. I don't know anything about accessing individual channels on the board. I glanced at the web page, but didn't readily see what you were talking about. You can read that information as well as I can.

I think you have enough to figure out what you need to do. To blink a light, just turn it on, wait, and turn it off. To use a specific channel, copy from code you find on the web page.
Topic archived. No new replies allowed.