Program Delay Action

Hi people,

I am new to electronics and my knowledge base is relatively limited so I am not sure this is proper place to ask my question, if so I apologize in advance.

I recently built a simple circuit using arrays and for loops and I came across this problem which has me baffled.

I am using a for loop to set the pins for the array as outputs and other for loop to simply turn on and then off a series of leds.

The array runs for a period of time fine, in my case roughly 13 times, before all the leds remain on for a pro-long period of time(roughly 8 seconds then turns off, wait roughly a second of so then turns all the less on and the hesitation starts over eventually leaving all the less lite.

I have no idea why this is happening since the code seems simple enough, can anyone tell me why this is happening?

Assistance is greatly appreciated.

my code:

int ledArray[] = {2,3,4,5,6,7}; // pins in the array
int Time = 75; // sets the on and off time

void setup() {
// initialize digital pins 2 through 7 as an output

for(int i; i <6; i++)
{
pinMode(ledArray*, OUTPUT);*

  • }*
    }
  • // turns on leds in sequence*
  • void loop()*
    {
  • for (int i=0; i<=6; i++) {*
    _ digitalWrite(ledArray*, HIGH);_
    _
    delay(Time);_
    _
    }_
    _
    for (int i=6; i>=0; i--) // turns off the leds in sequence*_
    * {*
    _ digitalWrite(ledArray*, LOW);
    delay(Time);
    }
    delay(1000);
    }*_

The code is missing the array indexing []

pinMode(ledArray[i], OUTPUT);

digitalWrite(ledArray[i], HIGH);

digitalWrite(ledArray[i], LOW);

Thanks for your response Cross Roads.

I changed the code as suggested(see revised code below) and although the run time tripled, the end result is the same, the code runs for a period of time ending with the leds remain on and the sequence stopped. It's got my head hurting :). I have tried changing boards from a nano, uno, and mega, the results are the same. Any other suggestions for why this might be happening?

Your assistance is greatly appreciated.

Revised code with indexing:

int ledArray[] = {2,3,4,5,6,7}; // pins in the array
int Time = 75; // sets the on and off time

void setup() {
// initialize digital pins 2 through 7 as an output

for(int i; i <6; i++)
{
pinMode(ledArray*, OUTPUT);*

  • }*
    }
  • // turns on leds in sequence*
  • void loop() {*
  • for (int i=0; i<=6; i++) {*
    _ digitalWrite(ledArray*, HIGH);_
    _
    delay(Time);_
    _
    }_
    _
    for (int i=6; i>=0; i--) // turns off the leds in sequence*_
    * {*
    _ digitalWrite(ledArray*, LOW);
    delay(Time);
    }
    delay(1000);
    }*_

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.