Incrementing pins

Hello all,

I’m wondering how this code works. I have two LED’s set to pin 1 and pin 12, I increment the pins from 1 to 12 and the LED’s both flash at the same time. Shouldn’t they flash at a slightly different time since the pins are increment? Thanks.

int pin = 1; 
void setup() 
{
  
  pinMode(pin, OUTPUT); 

}

void loop() 
{

  for (pin=1;pin<12;pin++)
  {
 digitalWrite(pin, HIGH);
 delay(100);
 digitalWrite(pin, LOW);
 delay(100);
  }
}

It must be your wiring, since pin 12 never gets set to OUTPUT with pinMode() and the highest pin that you write to is 11. Also, you do realize that pin 1 is used for serial communications?

Hmm you're right. I cleaned up the wiring and changed the code it is working properly now. I am using pins 2-7 now but there is one thing, the #7 pin LED is hardly flashing at all. It's so dim. What's up with that?

Also, I had no idea about serial communication...not sure what it is either. I better look into it.

Thanks.

Scotchdew:
Hmm you're right. I cleaned up the wiring and changed the code it is working properly now. I am using pins 2-7 now but there is one thing, the #7 pin LED is hardly flashing at all. It's so dim. What's up with that?

Also, I had no idea about serial communication...not sure what it is either. I better look into it.

Thanks.

Post your updated code.

is hardly flashing at all. It's so dim. What's up with that?

It's your code. It's wrong. Post it if you expect us to explain it.

Have you set it to an OUTPUT?

Alright after reading everyones posts and waiting for the 10 minutes post limit I figured it out.

int pin = 2; 
void setup() 
{
  
  
  for (pin = 2; pin<=8; pin++)// I didn't write this line before
  pinMode(pin, OUTPUT); 

}

void loop() 
{

  for (pin=2;pin<=8;pin++) //i thought this incremented output, but it does not
  {
 digitalWrite(pin, HIGH);
 delay(100);
 digitalWrite(pin, LOW);
 delay(100);
  }
}

The thing that confused me was when I didn’t increment output in the setup function, the 7 pin still lit, but just barely. I was wondering why it was still getting that little pulse of electricity?

Because writing it high as an input turns on the internal pull up resistor giving you just a tiny bit of current.