How do I use for statement to run the whole code twice, then stop

  • Thread starter Deleted member 750607
  • Start date

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
this is just out of curiosity...ive been fiddling with the for " (i=0; i < 2; i++) " statement for a while but its not stopping after 3 runs (three, not two, because the first run is zero)

im using arduino MKR wifi 1010 because my other boards are tied up

it just keeps repeating. I want it to stop after however many times (in this case 3, but any number will do)

why doesnt it seem to be counting? here's my code, its quite lengthy. its just a little LED light show, the important part is here in the beginning where I try to use the for statement...literally the rest is just flashing LEDs. Theres nothing important after the for statement.

THANKS

Code:
const int pin0 = 6;
const int pin1 = 7;
const int pin2 = 8;
const int pin3 = 9;
const int pin4 = 10;
const int pin5 = 11;
const int pin6 = 12;
const int pin7 = 13;
const int pin8 = 14;


void setup()
{
pinMode (pin0, OUTPUT);
pinMode (pin1, OUTPUT);
pinMode (pin2, OUTPUT);
pinMode (pin3, OUTPUT);
pinMode (pin4, OUTPUT);
pinMode (pin5, OUTPUT);
pinMode (pin6, OUTPUT);
pinMode (pin7, OUTPUT);
pinMode (pin8, OUTPUT);
}

void loop()
{
  int i = 0;
  for (i=0; i < 2; i++)
{
digitalWrite (pin0, HIGH);      //start chaser sequence
delay (250);
digitalWrite (pin0, LOW);

digitalWrite (pin1, HIGH);
delay (250);
digitalWrite (pin1, LOW);

digitalWrite (pin2, HIGH);
delay (250);
digitalWrite (pin2, LOW);

digitalWrite (pin3, HIGH);
delay (250);
digitalWrite (pin3, LOW);

digitalWrite (pin4, HIGH);
delay (250);
digitalWrite (pin4, LOW);

digitalWrite (pin5, HIGH);
delay (250);
digitalWrite (pin5, LOW);

digitalWrite (pin6, HIGH);
delay (250);
digitalWrite (pin6, LOW);

digitalWrite (pin7, HIGH);
delay (250);
digitalWrite (pin7, LOW);

digitalWrite (pin8, HIGH);
delay (250);
digitalWrite (pin8, LOW);




digitalWrite (pin0, HIGH);       //start first flash sequence

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);

digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);

digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);



digitalWrite (pin8, HIGH);        //start backward chaser sequence
delay (250);
digitalWrite (pin8, LOW);

digitalWrite (pin7, HIGH);
delay (250);
digitalWrite (pin7, LOW);

digitalWrite (pin6, HIGH);
delay (250);
digitalWrite (pin6, LOW);

digitalWrite (pin5, HIGH);
delay (250);
digitalWrite (pin5, LOW);

digitalWrite (pin4, HIGH);
delay (250);
digitalWrite (pin4, LOW);

digitalWrite (pin3, HIGH);
delay (250);
digitalWrite (pin3, LOW);

digitalWrite (pin2, HIGH);
delay (250);
digitalWrite (pin2, LOW);

digitalWrite (pin1, HIGH);
delay (250);
digitalWrite (pin1, LOW);

digitalWrite (pin0, HIGH);
delay (250);
digitalWrite (pin0, LOW);


digitalWrite (pin0, HIGH);           //start second flash sequence

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);

digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);

digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);



digitalWrite (pin4, HIGH);      //start first inside out chaser sequence
delay (250);
digitalWrite (pin4, LOW);

digitalWrite (pin3, HIGH);
delay (250);
digitalWrite (pin3, LOW);

digitalWrite (pin5, HIGH);
delay (250);
digitalWrite (pin5, LOW);

digitalWrite (pin2, HIGH);
delay (250);
digitalWrite (pin2, LOW);

digitalWrite (pin6, HIGH);
delay (250);
digitalWrite (pin6, LOW);

digitalWrite (pin1, HIGH);
delay (250);
digitalWrite (pin1, LOW);

digitalWrite (pin7, HIGH);
delay (250);
digitalWrite (pin7, LOW);

digitalWrite (pin0, HIGH);
delay (250);
digitalWrite (pin0, LOW);

digitalWrite (pin8, HIGH);
delay (250);
digitalWrite (pin8, LOW);


digitalWrite (pin8, HIGH);      //start second inside out chaser sequence
delay (250);
digitalWrite (pin8, LOW);

digitalWrite (pin0, HIGH);
delay (250);
digitalWrite (pin0, LOW);

digitalWrite (pin7, HIGH);
delay (250);
digitalWrite (pin7, LOW);

digitalWrite (pin1, HIGH);
delay (250);
digitalWrite (pin1, LOW);

digitalWrite (pin6, HIGH);
delay (250);
digitalWrite (pin6, LOW);

digitalWrite (pin2, HIGH);
delay (250);
digitalWrite (pin2, LOW);

digitalWrite (pin5, HIGH);
delay (250);
digitalWrite (pin5, LOW);

digitalWrite (pin3, HIGH);
delay (250);
digitalWrite (pin3, LOW);

digitalWrite (pin4, HIGH);
delay (250);
digitalWrite (pin4, LOW);



digitalWrite (pin4, HIGH);         //start first stagnant chaser inside out
delay (250);
digitalWrite (pin3, HIGH);
digitalWrite (pin5, HIGH);
delay (250);
digitalWrite (pin2, HIGH);
digitalWrite (pin6, HIGH);
delay (250);
digitalWrite (pin1, HIGH);
digitalWrite (pin7, HIGH);
delay (250);
digitalWrite (pin0, HIGH);
digitalWrite (pin8, HIGH);
delay (1000);



digitalWrite (pin8, LOW);         //start second stagnant chaser right side out
digitalWrite (pin0, LOW);
delay (250);
digitalWrite (pin7, LOW);
digitalWrite (pin1, LOW);
delay (250);
digitalWrite (pin6, LOW);
digitalWrite (pin2, LOW);
delay (250);
digitalWrite (pin5, LOW);
digitalWrite (pin3, LOW);
delay (500);
digitalWrite (pin4, LOW);
delay (250);




digitalWrite (pin0, HIGH);       //start third flash sequence

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);





digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);

digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);

digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);
digitalWrite (pin0, HIGH);

digitalWrite (pin1, HIGH);

digitalWrite (pin2, HIGH);

digitalWrite (pin3, HIGH);

digitalWrite (pin4, HIGH);

digitalWrite (pin5, HIGH);

digitalWrite (pin6, HIGH);

digitalWrite (pin7, HIGH);

digitalWrite (pin8, HIGH);

delay (25);

digitalWrite (pin0, LOW);

digitalWrite (pin1, LOW);

digitalWrite (pin2, LOW);

digitalWrite (pin3, LOW);

digitalWrite (pin4, LOW);

digitalWrite (pin5, LOW);

digitalWrite (pin6, LOW);

digitalWrite (pin7, LOW);

digitalWrite (pin8, LOW);

delay (25);




digitalWrite (pin0, HIGH);      //start fast chaser sequence
delay (50);
digitalWrite (pin0, LOW);

digitalWrite (pin1, HIGH);
delay (50);
digitalWrite (pin1, LOW);

digitalWrite (pin2, HIGH);
delay (50);
digitalWrite (pin2, LOW);

digitalWrite (pin3, HIGH);
delay (50);
digitalWrite (pin3, LOW);

digitalWrite (pin4, HIGH);
delay (50);
digitalWrite (pin4, LOW);

digitalWrite (pin5, HIGH);
delay (50);
digitalWrite (pin5, LOW);

digitalWrite (pin6, HIGH);
delay (50);
digitalWrite (pin6, LOW);

digitalWrite (pin7, HIGH);
delay (50);
digitalWrite (pin7, LOW);

digitalWrite (pin8, HIGH);
delay (50);
digitalWrite (pin8, LOW);


digitalWrite (pin8, HIGH);        //start second fast chaser sequence
delay (50);
digitalWrite (pin8, LOW);

digitalWrite (pin7, HIGH);
delay (50);
digitalWrite (pin7, LOW);

digitalWrite (pin6, HIGH);
delay (50);
digitalWrite (pin6, LOW);

digitalWrite (pin5, HIGH);
delay (50);
digitalWrite (pin5, LOW);

digitalWrite (pin4, HIGH);
delay (50);
digitalWrite (pin4, LOW);

digitalWrite (pin3, HIGH);
delay (50);
digitalWrite (pin3, LOW);

digitalWrite (pin2, HIGH);
delay (50);
digitalWrite (pin2, LOW);

digitalWrite (pin1, HIGH);
delay (50);
digitalWrite (pin1, LOW);

digitalWrite (pin0, HIGH);
delay (50);
digitalWrite (pin0, LOW);
}
}
 
Last edited by a moderator:

an_other

Joined Apr 22, 2021
2
C (Arduino) has a void(setup) section, and a void(loop) section - the loop section repeats 'forever' - so your routine inside void(loop) will repeat 3 times (as you say), then the void(loop section will end - then repeat.

if you add at the end of your code inside the void(loop) something like: (I only show the very end of the code inside your void(loop) section.
.....
digitalWrite (pin0, LOW);
} // end of 'for' loop
Loop_end:
goto Loop_end;
}

It will run the 3 loops, then simply keep looping around the 'Loop-end: goto Loop-end:'
Note this is quite crude - it all appears to stop, but the processor is in a never-ending loop which does nothing. The only way out (if you need to re-run it) is to press the reset (or power OFF - ON). There are better ways to do the same thing, but I guess you are still learning, so I'll leave it you. ;-)
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
C (Arduino) has a void(setup) section, and a void(loop) section - the loop section repeats 'forever' - so your routine inside void(loop) will repeat 3 times (as you say), then the void(loop section will end - then repeat.

if you add at the end of your code inside the void(loop) something like: (I only show the very end of the code inside your void(loop) section.
.....
digitalWrite (pin0, LOW);
} // end of 'for' loop
Loop_end:
goto Loop_end;
}

It will run the 3 loops, then simply keep looping around the 'Loop-end: goto Loop-end:'
Note this is quite crude - it all appears to stop, but the processor is in a never-ending loop which does nothing. The only way out (if you need to re-run it) is to press the reset (or power OFF - ON). There are better ways to do the same thing, but I guess you are still learning, so I'll leave it you. ;-)
go ahead and tell me if there are other ways. im just interested in learning!
 

djsfantasi

Joined Apr 11, 2010
7,914
hi,
Try
E
void loop()
{
int i = 1;
for (i=1; i < 2; i++)
That will ring the loop once. Once for I=1. Then,will be equal to 2 AND the for loop will exit.

But, the sketch will run again from the beginning, making it look like you’re stuck in the loop.

if you want the loop to run twice, which your original code will do, and then STOP, you have to insert code to prevent the sketch from running again.

Before the last brace in the sketch, insert the following line to see what will happen.
while (True);​

This will keep the sketch from running again, as it will get “caught” in the forever while loop.

An Arduino sketch repeats the main() code block once the end of code is reached. It’s what it does by definition.

Your original code runs, then runs again, then runs again, etc… Making it look like you’re stuck in the loop. When really your loop is stuck in main().

Edit; I see that while I was typing. Others pretty much said the same thing.

You could pretty it up by adding this line to the very beginning of your sketch
#define halt while(True);​
And then between the end of the loop and the end of the sketch, use this code
C:
    }
halt;
}
 
Last edited:

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
C (Arduino) has a void(setup) section, and a void(loop) section - the loop section repeats 'forever' - so your routine inside void(loop) will repeat 3 times (as you say), then the void(loop section will end - then repeat.

if you add at the end of your code inside the void(loop) something like: (I only show the very end of the code inside your void(loop) section.
.....
digitalWrite (pin0, LOW);
} // end of 'for' loop
Loop_end:
goto Loop_end;
}

It will run the 3 loops, then simply keep looping around the 'Loop-end: goto Loop-end:'
Note this is quite crude - it all appears to stop, but the processor is in a never-ending loop which does nothing. The only way out (if you need to re-run it) is to press the reset (or power OFF - ON). There are better ways to do the same thing, but I guess you are still learning, so I'll leave it you. ;-)
the only problem with what you showed me (loop end stuff) is that I am trying to make it repeat two or three times, THEN stop repeating the loop and do nothing
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
That will ring the loop once. Once for I=1. Then,will be equal to 2 AND the for loop will exit.

But, the sketch will run again from the beginning, making it look like you’re stuck in the loop.

if you want the loop to run twice, which your original code will do, and then STOP, you have to insert code to prevent the sketch from running again.

Before the last brace in the sketch, insert the following line to see what will happen.
while (True);​

This who’ll keep the sketch from running again, as it will get “caught” in the forever while loop.

An Arduino sketch repeats the main() code block once the end of code is reached. It’s what it does by definition.

your original code runs, then runs again, then runs again, etc… Making it look like you’re stuck in the loop. When really your loop is stuck in main().
this one tells me there's a syntax error when I do that, true was not declared
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
this one tells me there's a syntax error when I do that, true was not declared
yes, I fixed the capitalization and it works, but it doesn't solve my problem, I would like to know how to make it run twice or three times AND THEN stop

this way that you've shown me only lets it run once, I would like to know out of curiosity how to make it run 2-3 times, then stop
 

djsfantasi

Joined Apr 11, 2010
7,914
yes, I fixed the capitalization and it works, but it doesn't solve my problem, I would like to know how to make it run twice or three times AND THEN stop

this way that you've shown me only lets it run once, I would like to know out of curiosity how to make it run 2-3 times, then stop
You already how to make it run 2-3 times. You just might not realize it. The first for loop makes it run the desired number of times. The halt or while(True); stops after the number of loops. In general, the code to loop n times is this sample.

C:
n=3; // the number of times to loop

for(int i=0; i< n ; i++) {
  // code to 'loop'
}
halt;
}
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
You already how to make it run 2-3 times. You just might not realize it. The first for loop makes it run the desired number of times. The halt or while(True); stops after the number of loops. In general, the code to loop n times is this sample.

C:
n=3; // the number of times to loop

for(int i=0; i< n ; i++) {
  // code to 'loop'
}
halt;
}
this looks promising, unfortunately its asking me to declare "halt" and Im not sure how to do that properly (still a newbie)

:)
 
Last edited by a moderator:

djsfantasi

Joined Apr 11, 2010
7,914
this looks promising, unfortunately its asking me to declare "halt" and Im not sure how to do that properly (still a newbie)

:)
Refer back to my earlier reply, when I defined halt. You probably omitted the step where halt was defined in the sketch. At the beginning of the sketch, add the line which follows. It defines halt.

#define halt while(True)
 

djsfantasi

Joined Apr 11, 2010
7,914
Listen for a second. You have to learn how to build on your knowledge. Information is being presented to you in steps. You need to recognize this.
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
Refer back to my earlier reply, when I defined halt. You probably omitted the step where halt was defined in the sketch. At the beginning of the sketch, add the line which follows. It defines halt.

#define halt while(True)
Great! it works!

I was trying to figure out how to do that, you use #define...

is the while(true) part kind of a "hack" if you will? im a little confused about that part

do you still need the for statement?
 

djsfantasi

Joined Apr 11, 2010
7,914
Re-read post #11 and you tell me if you need the for statement. I feel like I’ve answered your question more than once. Hence, it is possible that you’re not understanding the code. Re-read post #11 and you’ll learn more if you answer your own question.
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
Re-read post #11 and you tell me if you need the for statement. I feel like I’ve answered your question more than once. Hence, it is possible that you’re not understanding the code. Re-read post #11 and you’ll learn more if you answer your own question.
I understand the code perfectly fine. its just keeping track of all these answers, jumping around on the thread is confusing
 

djsfantasi

Joined Apr 11, 2010
7,914
Great! it works!

I was trying to figure out how to do that, you use #define...

is the while(true) part kind of a "hack" if you will? im a little confused about that part

do you still need the for statement?
No, it’s NOT a hack. It’s one way of how you force the Arduino (and other υP) to stop executing any other code.
 

djsfantasi

Joined Apr 11, 2010
7,914
I understand the code perfectly fine. its just keeping track of all these answers, jumping around on the thread is confusing
So answer your own question! Do you still need the for statement? It should be easy to answer because you understand the code so well.

(Sorry for any attitude. I’m trying to make a point)
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
thanks for the help, I'm not going to sit here and be scolded, im an adult who isn't very advanced in writing code, not your child
 
Top