Led Sketch

I am using the sketch:

int pinArray = {22, 23, 24, 25, 26, 27, 28, 29, 30};
int count = 0;
int timer = 30;

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

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

To blink LEDs like on knight rider. What I was wondering was if it is possible to run 3 of these sketches at a time. The idea is one bar of 8 LEDs will run by itself and 2 bars of 10 LEDs will run parallel up and down past each other. Help will be appreciated. Thanks.

Sorry if I lacked any detail you need.

First thing - you have 9 elements in your array, you are only setting up 8 as OUTPUT tho.

Yes, you can run multiple LED bars at the same time. Look at LED cubes - folks make 8x8, my wife & I are making a 9x9, that is 64 & 81 LEDs per layer. Two bars of 8 and a bar of 10 are easily possible. Look at blink-without-delay code to see how to have each running on its own timing as well if you want them running independently.

Yes, there are many ways to do that, Shifter-register, I2C I/O expanders, etc. This is very used in led cubs and led displays.

I write a little sketch this morning that does something like what yours do. My approach it’s a little different.

#define LENGTH 4
int output[] = {31, 33, 35, 37};
int count;

void setup() {
  for (int i=0; i<LENGTH; i++) {
     pinMode(output[i], OUTPUT);
  }
}

void loop() {
  if (count < LENGTH) {
     digitalWrite(output[count], HIGH);
  }
  else {
     digitalWrite(output[count-LENGTH], LOW);
  }
  
  if (++count >= 2*LENGTH) {
     count = 0;
  }
  
  delay (500);

}

I don't know why, but I was thinking that your problem was the hardware (less outputs than led's). Now that I think about and realise that is not to hard and I came to write the answer, I've read another time your first post and I understand that your problem is the code, right?

Can you explain what is your idea? From your description I don't understand very well what the code must do.

The representation of the led's is this:

   *  *  *  *  *  *  *  *  *  *
      #  #  #  #  #  #  #  #
   +  +  +  +  +  +  +  +  +  +

What you mean by: "past each other"? First goes on the "*" and then the "+" at the same time that "#" is on?

Well my plan was really having something like this if you can understand it:

LED bar 1 : + + + + + + + +

This LED bar runs from left to right over and over while the other 2:

LED Bar 2: = LED Bar 3: - Bar 2 runs from = to - while at the same time Bar 3 + + Runs from - to = passing each other meeting close + + to the middle. + + + + + + + + + + + + - =

Hopefully you get my idea this time and thanks a lot for the help so far.

Ok. Now I understand what you want and it’s easiest that it may look. Ba2 and Bar3 are the same thing but hey are upside-down! You can peak the signal from the first led in the Bar2 and connect it to the last led of the Bar3. Peak the signal from the second led in the Bar2 and connect it to the penultimate led of the Bar3. And so on.
Your really problem is to have the 2 “programs” running at the same time.

EDIT: After I write my last reply, I wrote a program that make the same thing that you are doing in the “original” program but with the method that I use in my example. That’s what it look like:

#define LENGTH 8
int output[] = {31, 33, 35, 37, 39, 41, 43, 45};
int count;
boolean forward = true;

void setup() {
  for (int i=0; i<LENGTH; i++) {
     pinMode(output[i], OUTPUT);
  }
}

void loop() {

  if (forward) {
     digitalWrite(output[count], HIGH);
     if (count > 0 ) {
        digitalWrite(output[count-1], LOW);
     }
  }
  else {
     digitalWrite(output[LENGTH-count-1], HIGH);
     if (count > 0 ) {
        digitalWrite(output[LENGTH-count], LOW);
     }  
  }
  ++count;
  if ( count >= LENGTH ) {
     count = 1;
     if (forward) forward = false;
     else {
        forward = true;
     }
  }
  delay (100);
}

If I understand right what you want to do is this.

The code for this is:

#define LENGTH1 4
int output1[] = {31, 33, 35, 37};
int count1;
boolean forward1 = true;

#define LENGTH2 5
int output2[] = {30, 32, 34, 36, 38};
int count2;
boolean forward2 = true;

void setup() {
  int i;
  for (i=0; i<LENGTH1; i++) {
     pinMode(output1[i], OUTPUT);
  }
  for (i=0; i<LENGTH2; i++) {
     pinMode(output2[i], OUTPUT);
  }
}

void loop() {

  if (forward1) {
     digitalWrite(output1[count1], HIGH);
     if (count1 > 0 ) {
        digitalWrite(output1[count1-1], LOW);
     }
  }
  else {
     digitalWrite(output1[LENGTH1-count1-1], HIGH);
     if (count1 > 0 ) {
        digitalWrite(output1[LENGTH1-count1], LOW);
     }  
  }
  ++count1;
  if ( count1 >= LENGTH1 ) {
     count1 = 1;
     if (forward1) forward1 = false;
     else {
        forward1 = true;
     }
  }
  
  if (forward2) {
     digitalWrite(output2[count2], HIGH);
     if (count2 > 0 ) {
        digitalWrite(output2[count2-1], LOW);
     }
  }
  else {
     digitalWrite(output2[LENGTH2-count2-1], HIGH);
     if (count2 > 0 ) {
        digitalWrite(output2[LENGTH2-count2], LOW);
     }  
  }
  ++count2;
  if ( count2 >= LENGTH2 ) {
     count2 = 1;
     if (forward2) forward2 = false;
     else {
        forward2 = true;
     }
  }
  
  delay (200);
}

It can be made in a better way, but it’s working.

PS: I’m sorry for the bad video, but is the only camera that I have.

Thanks for the help, im glad someone understood my plan
the video was great. Sorry for the lack of replies. I have been trying to save some internet credit.

Thanks