code.. pause time.

Hi Guys,

I have this code, for a random 8 lights effect. What can I do, so that I can run the loop for say.. 10 minutes, and than it stops. It should restart after another..say..15 minutes, and stops again for 10 minutes.

Thanks.

int pinArray[] = {2, 3, 4, 5, 6, 7, 8, 9};
int count = 0;
int timer = 80;

void setup(){
for (count=0;count<8;count++) {
pinMode(pinArray[count], OUTPUT);
}
}

void loop() {
for (count=0;count<8;count++) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count + 3], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer2);
}
for (count=8;count>0;count--) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count - 1], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer
2);

}

for (count=0;count<7;count++) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count + 1], HIGH);
delay(timer);
digitalWrite(pinArray[count], HIGH);
delay(timer2);
}
for (count=6;count>0;count--) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count - 1], LOW);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer
2);

}
for (count=0;count<6;count++) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count + 1], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer2);
}
for (count=5;count>0;count--) {
digitalWrite(pinArray[count], HIGH);
delay(timer
5);
digitalWrite(pinArray[count - 1], LOW);
delay(timer);
digitalWrite(pinArray[count], HIGH);
delay(timer*5);

I started to edit your post to add code tags, then realised the code was incomplete.

You can add the code tags when you post the complete code.

You will probably need to replace all the delay()s with millis() as illustrated in several things at a time. Millis() can then be used to add the extra timing that you want.

Move the existing code into a function (perhaps call it flashLEDs() )and just have something like this in loop()

void loop() {
   if (millis() - startMillis >= intervalMillis) {
       if (lightsWorking == false) {
            lightsWorking = true;
       }
      else {
         lightsWorking = false;
      }
    startMillis += intervalMillis;
   }
}

and at the top of your new flashLEDs() function add

void flashLEDs() {
   if (lightsWorking = false) {
      return;
   }
   // rest of the flashing code
)

...R

If you want it to just sit there waiting, totally dead and unresponsive until the 15 minutes has expired, then

  delay(15*60*1000);

MorganS:
If you want it to just sit there waiting, totally dead and unresponsive until the 15 minutes has expired, then

  delay(15*60*1000);

Nope. Try again.

  15*60*1000

Using the arithmetic we all learned in school, that equals 900000.

The Arduino does not use the arithmetic we all learned in school.

Try this instead:

  15*60*1000L

Thanks for your replies..

The delay command has 1 problem, that it only executes the loop once.. (which lasts for few seconds).. than halts for the time in delay. I would like to run the loop for say 3 minutes, before it stops the loop, and restarts after 5 minutes.

Also I have noted something in this code.. and I have NO IDEA were the mistake is.. It starts running very good, but after a couple of minutes, it seems like its adding the delay time by its own.. making it run slow.. and slower.. and slower.. (sometimes even 5 seconds from 1 count to the other!!)
Other times, it just freezes in half a loop (leaving some LED.s High)
I tried to upload another sketch, a more simple Knightrider sketch.. and it works fine. So, I am eliminating the fact that it could be the actual Arduino Board.

This is the complete code, as apparently it did not appear all of it the first time

int pinArray[] = {2, 3, 4, 5, 6, 7, 8, 9};
int count = 0;
int timer = 40;

void setup(){
  for (count=0;count<8;count++) {
    pinMode(pinArray[count], OUTPUT);
  }
}

void loop() {
 for (count=0;count<8;count++) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count + 3], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   delay(timer*2);
  }
  for (count=7;count>0;count--) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count - 1], LOW);  //HIGH
   delay(timer);
   digitalWrite(pinArray[count], HIGH);      //LOW
   delay(timer*2);
   
  }




  for (count=0;count<8;count++) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count + 1], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], HIGH);
   delay(timer*2);
  }
  for (count=7;count>0;count--) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count - 1], LOW);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   delay(timer*2);
   
  }
for (count=0;count<7;count++) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count + 1], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   delay(timer*2);
  }
  for (count=6;count>0;count--) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer*5);
   digitalWrite(pinArray[count - 1], LOW);
   delay(timer);
   digitalWrite(pinArray[count], HIGH);
   delay(timer*5);
  
  }
   
  }

The Arduino does not use the arithmetic we all learned in school.

It does use the same arithmetic, just a slightly restricted set.

OT: I got into my car this morning and the odometer read "65535" - I half expected it to roll-over as I drove down the road :slight_smile:

AWOL:
OT: I got into my car this morning and the odometer read "65535" - I half expected it to roll-over as I drove down the road :slight_smile:

"Traditional" odometer, or electronic display?

Electronic. Haven't seen a mechanical odometer in over twenty years!

digitalWrite(pinArray[count + 3], HIGH);

When count is equal to any value greater than 4, you are writing to (almost) random pins. Do you want to do that? Your array subscript is out of range.

yes, I noted.. it was a mistake.. actually, it was literally jamming and slowing down. :slight_smile:

Thanks.