Using outputs on mega

hi all im new to this forum im wanting some help and advice if possible iv got a mega and want to use all outputs to controlled via 1 input

soon as input is trigger the outputs will start switching on 1 by 1

Give us more information of exactly what you want?

something like this?

void setup()
{
  pinMode(2, INPUT);
  for (int i=3; i< 45; i++) pinMode(i, OUTPUT);
}

void loop()
{
  for (int i=3; i< 45; i++) digitalWrite(i, digitalRead(2) );
}

Hi sorry basically I’m looking to activate using 1 input and all the outputs go on one by one a second or so apart

Add delay(1000); after the for loop that robtillaart gave. Define "go on"?

Soon as 1 input is triggered via a relay contact from my firing box all the outputs will turn on 1 after another with a few second gap between

Change:
for (int i=3; i< 45; i++) digitalWrite(i, digitalRead(2) );
To
for (int i=3; i< 45; i++) digitalWrite(i, LOW );

However, they will stay low for ever, unless you add some code to turn them high.

madbiker2012: Hi sorry basically I'm looking to activate using 1 input and all the outputs go on one by one a second or so apart

The demo several things at a time shows how to time things without using delay() because delay() paralyzes the Arduino until the time is up.

This Thread Planning and Implementing a Program may also be of interest.

I suspect your project has more to it than simply making 20 or 30 I/O pins go HIGH at 1 second intervals and stay high forever. It would help if you give us the full picture. Maybe there is a better approach.

...R

Hi thank you for everyone trying to help

It's going to be used as a firework mine sequence press the button once the input has been trigger it will start to fire e-matches from all the outputs 1 after another

madbiker2012: It's going to be used as a firework mine sequence press the button once the input has been trigger it will start to fire e-matches from all the outputs 1 after another

That sounds like it really does only need to run once. And if so it would make perfect sense to use delay() between the steps to give the correct timing.

...R

while (digitalRead (TRIGGER) == HIGH)   // or LOW depending on how you wired things up
  {  }  // wait for trigger

for (int i = 3; i < 20; i++)
  {
  digitalWrite (i, HIGH);
  delay (1000);
  }

@madbiker2012

Have you thought about how to handle the start of the Arduino? e.g. to be sure that you need more than one signal before start?

so you get some state sequence like

SAFE - (special code e.g. 5 second keypress of 2 buttons OR electric lock with key) - ARMED - (push button) - FIRE

instead of

ARMED - (push button) - FIRE