Pin alias so I don't need to change code or rewire

Hey,

I have a xmas light controller I made. It originally flipped a set of 8 relays on and off to make light patterns. Like so:

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


void loop()                     
{    
 // wave up 
      
  for(int x = 1; x<=4; x++)  {
            
      for(int i = 1; i <= 8; i++) {
        digitalWrite(i, HIGH);
        delay(500);
      }
      for(int i = 0; i <= 8; i++) {
        digitalWrite(i, LOW);
        delay(500);
      } 
      delay(2000);
  }
etc, more patterns

Problem is relays 1 and 7 have burned out. I could go in and rewire the thing. I could just run it as is and not use 1 and 7.

What I want to know is if there is some sort of alias I can assign in my set up to just use pins 2, 3, 4, 5, 6, and 8 without having to drastically rewrite everything. All the patterns would then run as x<= 3 and i < 6 is my idea.

In the setup can I do something like
pin1= 2
pinMode(pin1, OUTPUT)

and then in the loops do something like
digitalWrite("pin" + i, OUTPUT)
??

Obviously, I don't have the correct syntax.

Many thanks in advance.

and then in the loops do something like
digitalWrite("pin" + i, OUTPUT)
??

Not like that. Names do not exist in the compiled code, so you can't set the mode based on the name.

Using an array of pin numbers, and iterating in the loops over the pins in the array, based on the sizeof the array means that when you replace the burned out relay (how DID that happen?), you just add another pin number to the array, and no other changes are needed.

Ah ha! An array.

So my setup then looks like:

int myPins[] = {2, 3, 4, 5, 6, 8};

for(int i = 1; i <= 6; i++) {
    pinMode(myPins[i], OUTPUT);
  }

And my loops do

digitalWrite(myPins[i], HIGH);
etc

That right?

Oh, and inexpensive foreign product running outside for a couple of weeks is how a relay fails.

So my setup then looks like

No, because the compiler can count better than you.

What happens if you add a pin? You have to change the 6 everywhere. Let the compiler do that.

Oh, and array indices start at 0.

byte myPins[] = {2, 3, 4, 5, 6, 8};
byte pinCount = sizeof(myPins) / sizeof(myPins[0]);

for(int i = 0; i < pinCount; i++)
{
    pinMode(myPins[i], OUTPUT);
}

Oooooo. So then I could also do

for(int i = 0; i <= pinCount; i++) {
digitalWrite(myPins[i], HIGH);
etc

if I am following you correctly.

Hmm. I'm got

pinCount was not declared in this scope.

Put the two byte declarations outside of setup to make them global and it compiled.

I think I have functional code.

Thank you very much.