interrrupt with timed LEDs

hi ! i have my code here. but i just don't know how to start "ledPins9 and ledPins10" to turn on at the same time ( ledPins9 for 8 minutes ON and ledPins10 for 5 minutes ON)
Here's my code:

int ledPins[] = { 3,4,5,6,7,8,9,10,11,12,13 };
int pinCount = 11;
int switchPin = 2; // digital Pin2
int inputPin = switchPin;
int pirState = LOW;
int val = 0;
void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPins[0], OUTPUT);
pinMode(ledPins[1], OUTPUT);
pinMode(ledPins[2], OUTPUT);
pinMode(ledPins[3], OUTPUT);
pinMode(ledPins[4], OUTPUT);
pinMode(ledPins[5], OUTPUT);
pinMode(ledPins[6], OUTPUT);
pinMode(ledPins[7], OUTPUT);
pinMode(ledPins[8], OUTPUT);
pinMode(ledPins[9], OUTPUT);
pinMode(ledPins[10], OUTPUT);
pinMode(ledPins[11], OUTPUT);
Serial.begin(9600);
}
void loop()
{
val = digitalRead(inputPin);
if (val == HIGH) {
digitalWrite(ledPins[1], HIGH);
delay(1500);
digitalWrite(ledPins[1], LOW);
digitalWrite(ledPins[2], HIGH);
delay(1500);
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[3], HIGH);
delay(1500);
digitalWrite(ledPins[3], LOW);
digitalWrite(ledPins[4], HIGH);
delay(1500);
digitalWrite(ledPins[4], LOW);
digitalWrite(ledPins[5], HIGH);
delay(1500);
digitalWrite(ledPins[5], LOW);
digitalWrite(ledPins[6], HIGH);
delay(1500);
digitalWrite(ledPins[6], LOW);
digitalWrite(ledPins[7], HIGH);
delay(1500);
digitalWrite(ledPins[7], LOW);
digitalWrite(ledPins[8], HIGH);
delay(1500);
digitalWrite(ledPins[8], LOW);
digitalWrite(ledPins[9], HIGH);
delay(8000);
digitalWrite(ledPins[9], LOW);
digitalWrite(ledPins[10], HIGH);
delay(5000);
digitalWrite(ledPins[10], LOW);
digitalWrite(ledPins[11], HIGH);
delay(1500);

digitalWrite(ledPins[11], LOW);
}
else
{
digitalWrite(ledPins[1], LOW);
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[3], LOW);
digitalWrite(ledPins[4], LOW);
digitalWrite(ledPins[5], LOW);
digitalWrite(ledPins[6], LOW);
digitalWrite(ledPins[7], LOW);
digitalWrite(ledPins[8], LOW);
digitalWrite(ledPins[9], LOW);
digitalWrite(ledPins[10],LOW);
digitalWrite(ledPins[11],LOW);
}
}
PLEASE HELP ME. Thanks in advance...

pinMode(ledPins[0], OUTPUT);
pinMode(ledPins[1], OUTPUT);
pinMode(ledPins[2], OUTPUT);
pinMode(ledPins[3], OUTPUT);
pinMode(ledPins[4], OUTPUT);
pinMode(ledPins[5], OUTPUT);
pinMode(ledPins[6], OUTPUT);
pinMode(ledPins[7], OUTPUT);
pinMode(ledPins[8], OUTPUT);
pinMode(ledPins[9], OUTPUT);
pinMode(ledPins[10], OUTPUT);
pinMode(ledPins[11], OUTPUT);

The reason for using arrays is so you can use a for loop, and have 4 lines for code, instead of 12.

int ledPins[] = { 3,4,5,6,7,8,9,10,11,12,13 };
int pinCount = 11;

So, the indexes are 0 to 10, not 0 to 11.

This:

pinMode(ledPins[0], OUTPUT);
pinMode(ledPins[1], OUTPUT);

and this:

Serial.begin(9600);

never go in the same sketch.

int switchPin = 2; // digital Pin2
int inputPin = switchPin;

Why do you need two variables to hold one value? Why is pin 2 both an output and an input? You go some kind of weird Arduino clone?

You are not using the internal pullup resistor, so you must have an external pullup or pulldown resistor. Do you? How is the switch wired? Why is it wired in a more complicated way than it needs to be?

but i just don't know how to start "ledPins9 and ledPins10" to turn on at the same time

Get rid of the 8 second delay between turning them on.

ledPins9 for 8 minutes ON and ledPins10 for 5 minutes ON)

To do that, Ctrl-A to select everything, Ctrl-X to delete everything, and start of AFTER reading, understanding, and embracing the blink without delay example. The last step can not be emphasized enough. You can't just replace delay() with a roll-you-own variety using millis(). You must completely rethink how the code is written.

How would you, given a watch (millis()), a pad of paper (some variables), and a pen (the means to set the variables), turn two pins on at an arbitrary time, and turn them off at two different times, later?

thanks for the corrections. my code is a little bit cleaner.
but if i remove one line of the below code, my circuit doesnt work. let's just leave it as is.

int switchPin = 2; // digital Pin2
int inputPin = switchPin

I need to embrace :slight_smile: certain delays of LEDs because I'm going to use them for some circuits...
(for now I need to have at least 2 of the LEDs turn on at the same time in different duration)...

by the way I'm using resistor for the switch. (later on I will replace it with a positive signal 5v to pin2 of Arduino

I need to embrace smiley certain delays of LEDs because I'm going to use them for some circuits..

Utter rubbish - do as PaulS said or you CAN'T DO WHAT YOU WANT.

Mark

PLEASE HELP ME. Thanks in advance...

Help us by following the instructions below:

click the MODIFY button in the upper right of the post window.
Highlight all you code.
click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button.
click SAVE (at the bottom).
When you post code on the forum, please make a habit of using the code tags "#" button.

PaulS:
This:

pinMode(ledPins[0], OUTPUT);

pinMode(ledPins[1], OUTPUT);



and this:


Serial.begin(9600);



never go in the same sketch.

i don't see the conflict. As long as neither of ledPins[0] and [1] are 0 or 1, what goes wrong?

i don't see the conflict. As long as neither of ledPins[0] and [1] are 0 or 1, what goes wrong?

I don't wither. What idiot suggested that? :). Must not have been paying attention...