Looping through relay outputs using arrays?

Hi all,

I'm trying to work out if an array is the best way of achieving this task, and I've not used them before. I've found some things on using arrays to initialise pins and write to them but I'm new to arrays and a bit confused.

If i declare an array with the pins that are outputs like so:

//array for trap output pins
int trapPins[] = {A0, A1, 6};

What I want to do is write a loop that turns

A0 on/delay/off X number of times
A1 on/delay/off X number of times
D6 on/delay/off X number of times

each time an input is pulsed.

ie. if X = 3 pulse input A0 when triggered, pulse input A0 when triggered, pulse input A0 when triggered. Move on to A1, repeat cycle, then move on to D6

Hope that sort of makes sense. I started doing it as a nest of if statements but it's way too messy and worse if I expand it to 8 outputs.

To give some idea of what I'm doing the code I had written to go through the first loop is:

//On each time releaseState is 1 (comes from an input) the output needs to active a relay output 
//After (tokenCount) times the first relay is pulsed on, the loop needs to move to the next relay
//output and pulse it (tokenCount) times

//tokenCount is determined prior to startStopState being made == 1
//tokenCount determines how many times each output is repeated before moving on to the next output


if (releaseState == 1 && startStopState == 1) 
  {  
    if (trapRepeat <= tokenCount)
    {  
    Serial.print("Trap A : traprepeat = "), 
    Serial.println(trapRepeat);
 
    digitalWrite(trapCurrent, releaseState);
    delay(500);
    releaseState = 0;
    digitalWrite(trapCurrent, releaseState); 
    delay(40);

    trapRepeat++;
    totaliser++;
    }
    
      
  }
 
}

Thanks

Dave

Very hard to understand what you need. From what I read and understood

byte trap_pins[] = {A0, A1, 6};

#define how_many_times 5

void looper(byte,byte,byte);

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
  looper(how_many_times, trap_pins, (byte)(sizeof(trap_pins) / sizeof(trap_pins[0])));
}

void looper(byte x, byte trap_pins[], byte _size) {

  for (byte a = 0; a < _size; a++) {

    for (byte i = 0; i < x; i++) {

      digitalWrite(trap_pins[a], HIGH);

      delay(500);

      digitalWrite(trap_pins[a], LOW);

      delay(500);
    }
  }
  return;
}

Been playing around...

Getting closer. This will cycle the relays but second cycle stops after one activation.

if (releaseState == 1 && startStopState == 1) 
  {  
    if (trapRepeat <= tokenCount)
    {  
    Serial.print("Trap A : traprepeat = "), 
    Serial.println(trapRepeat);
    pinMode (trapPins[whichTrap], OUTPUT);
    digitalWrite(trapPins[whichTrap], releaseState);
    delay(500);
    releaseState = 0;
    digitalWrite(trapPins[whichTrap], releaseState); 
    delay(40);

    trapRepeat++;
    totaliser++;
    }
    if (trapRepeat == tokenCount)
    {
          whichTrap++;
          Serial.print("Which trap = "), 
          Serial.println(whichTrap);
    }

    }

 
}