For Loops Not Working

I am using for loops to flash two series of LEDs in an alternating pattern. I uploaded my code and for some reason it is not looping through each for loop as many times as I have it set to. It only loops through the whole void loop()… I have attached a copy of the code I wrote for this. I’m a newbie at for loops so does anyone see any errors or things to fix???

//declare all pins
const int led2 = 2;
const int led3 = 3;
const int led4 = 4;
const int led5 = 5;
const int led6 = 6;
const int led7 = 7;
const int led8 = 8;
const int led9 = 9;
const int led10 = 10;
const int led11 = 11;
int t1=35;
int t2=50;
int t3=75;
int t4=100;
int t5=200;

void setup(){
int thisPin=2;
for(thisPin=2; thisPin<=13; thisPin++);{
pinMode(thisPin, OUTPUT);
}
}

void loop(){
for(int j=1; j<=6; j=j+1);{
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led5, HIGH);
delay(t5);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led5, LOW);
delay(t5);
}

for(int j=1; j<=6; j=j+1);{
digitalWrite(led4, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
delay(t5);
digitalWrite(led4, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
delay(t5);
}
}

the loop() function will repeat over and over again.

if you want to do just the 6 flashes, you can put it in a function and call it from Setup like this. The setup() function runs only once.

//declare all pins
const int led2 = 2;
const int led3 = 3;
const int led4 = 4;
const int led5 = 5;
const int led6 = 6;
const int led7 = 7;
const int led8 = 8;
const int led9 = 9;
const int led10 = 10;
const int led11 = 11;
int t1=35;
int t2=50;
int t3=75;
int t4=100;
int t5=200;

void setup()
{
  int thisPin=2;
  for(thisPin=2; thisPin<=13; thisPin++);
  {
    pinMode(thisPin, OUTPUT);
  }
  flashLeds();
}

void loop()
{

}

void flashLeds()
{
  for(int j=1; j<=6; j=j+1);
  {
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led5, HIGH);
    delay(t5);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led5, LOW);
    delay(t5);
  }

  for(int j=1; j<=6; j=j+1);
  {
    digitalWrite(led4, HIGH);
    digitalWrite(led6, HIGH);
    digitalWrite(led7, HIGH);
    delay(t5);
    digitalWrite(led4, LOW);
    digitalWrite(led6, LOW);
    digitalWrite(led7, LOW);
    delay(t5);
  }
}

BulldogLowell:
the loop() function will repeat over and over again.

if you want to do just the 6 flashes, you can put it in a function and call it from Setup like this. The setup() function runs only once.

//declare all pins

const int led2 = 2;
const int led3 = 3;
const int led4 = 4;
const int led5 = 5;
const int led6 = 6;
const int led7 = 7;
const int led8 = 8;
const int led9 = 9;
const int led10 = 10;
const int led11 = 11;
int t1=35;
int t2=50;
int t3=75;
int t4=100;
int t5=200;

void setup()
{
 int thisPin=2;
 for(thisPin=2; thisPin<=13; thisPin++);
 {
   pinMode(thisPin, OUTPUT);
 }
 flashLeds();
}

void loop()
{

}

void flashLeds()
{
 for(int j=1; j<=6; j=j+1);
 {
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   digitalWrite(led5, HIGH);
   delay(t5);
   digitalWrite(led2, LOW);
   digitalWrite(led3, LOW);
   digitalWrite(led5, LOW);
   delay(t5);
 }

for(int j=1; j<=6; j=j+1);
 {
   digitalWrite(led4, HIGH);
   digitalWrite(led6, HIGH);
   digitalWrite(led7, HIGH);
   delay(t5);
   digitalWrite(led4, LOW);
   digitalWrite(led6, LOW);
   digitalWrite(led7, LOW);
   delay(t5);
 }
}

Bulldog! I’m surprised at you. Take out those semicolons from the end of the for loop statements :slight_smile:

It’s nice to see someone else making the mistake for a change :;

You need to leave out the semicolons

for(int j=1; j<=6; j=j+1); doesn’t work

just checking to see if you are checking

:blush:

whoops

  for(thisPin=2; thisPin<=13; thisPin++);

It’s everywhere!

http://www.gammon.com.au/forum/?id=12153#trap13

right… rub it in!!!

at least I can see the karma button :smiley:

Ghosts in the machine!

This is why the removed the edit facility. They want to see us squirm :slight_smile:

EDIT! HEY LOOK WE CAN EDIT AGAIN!

This is why the removed the edit facility. They want to see us squirm :slight_smile:

That's it, that's it, now I see why.

It makes perfect sense now.

BulldogLowell:
right... rub it in!!!

at least I can see the karma button :smiley:

Huh? That wasn't your code. :slight_smile:

The original had it for every for loop.

This is why the removed the edit facility. They want to see us squirm :slight_smile:

These are not the droids you are looking for.

We've logged a bug report about that. To be honest, there is quite a backlog of bug reports right now. :stuck_out_tongue:

No, I just telegraphed it into my edit, which may be worse :confused:

It’s easy to miss when:

 for(thisPin=2; thisPin<=13; thisPin++);{
  • You* don’t use code tags, in defiance of Starfleet Regulations; and
  • You have the brace on the same line as the if
  • By “you” I am not referring to BulldogLowell.

But getting back to the point.

jodyboehs:
I am using for loops to flash two series of LEDs in an alternating pattern. I uploaded my code and for some reason it is not looping through each for loop as many times as I have it set to. It only loops through the whole void loop()...... I have attached a copy of the code I wrote for this. I'm a newbie at for loops so does anyone see any errors or things to fix????

No sorry, we can't find anything wrong with it.

Apart from everything we mentioned above. :stuck_out_tongue: