A better way to code high/low sequences?

I’ve got a project with lots of LEDs wired in to several channels. For example, one section has 12 circuits, each circuit is comprised of 16 LEDs. The LEDs/circuits are in rows, wired so that one circuit hits every 4th LED. This way I can turn on circuit 1 for say .2sec, turn it off, then turn on circuit 2, then off, etc. over and over again and it does the moving/running light look. I’ve done this on other projects but it’s just getting to be so cumbersome with the coding, but I’m not savvy enough to figure out any other way. which is why i'm here :slight_smile: Basically for the coding I just use the On/Off (High/Low) commands to turn on/off each circuit in the specific order i want for the effect i'm going for. So I usually have to create a schedule to map out every circuit, how long they need to be on/off, and in what order. So my codes are HUGE, like 2000+ lines of just High/Low commands, but I can’t find ANY other examples of projects and/or codes like mine, so I don’t know if there is any better way of doing what I’m doing (if i have to change one thing it can take a long time and a lot of rewriting code). And I don’t just do one series/pattern, I like to mix it up, change the on/off times, delays, channel sequencing, to do different effects. An example of my code is below, as well as a link to a YouTube video of one of my displays and the different effects/sequencing I incorporate. So, is there a better way to do this? or am I stuck with just a whole bunch of on/off coding in my future? Thank you!!

Oh, also, there is no multiplexing or serial comm. or anything like that going on. These are one for one channels on the Arduino. I use PnP Transistors as switches to source power from another power source to power all the LEDs. So, the Arduino is just turning on/off a bunch of switches, turning on/off all the LED circuits.

My X-mas tree: LED Christmas Tree - YouTube

void setup() {
  
  pinMode(2, OUTPUT); //petal 1 W
  pinMode(3, OUTPUT); //petal 1 R
  pinMode(4, OUTPUT); //petal 1 W
  pinMode(5, OUTPUT); //petal 1 R
  pinMode(6, OUTPUT); //petal 2 R
  pinMode(7, OUTPUT); //petal 2 W 
  pinMode(14, OUTPUT); //petal 2 R
  pinMode(15, OUTPUT); //petal 2 W
  pinMode(16, OUTPUT); //petal 3 R
  pinMode(17, OUTPUT); //petal 3 W 
  pinMode(18, OUTPUT); //petal 3 R
  pinMode(19, OUTPUT); //petal 3 W
  pinMode(20, OUTPUT); //petal 4 W
  pinMode(21, OUTPUT); //petal 4 R
  pinMode(22, OUTPUT); //petal 4 W
  pinMode(24, OUTPUT); //petal 4 R
  pinMode(26, OUTPUT); //petal 5 R
  pinMode(28, OUTPUT); //petal 5 W
  pinMode(30, OUTPUT); //petal 5 R
  pinMode(32, OUTPUT); //petal 5 W
  pinMode(34, OUTPUT); //center W
  pinMode(36, OUTPUT); //center R
  pinMode(38, OUTPUT); //center W
  pinMode(40, OUTPUT); //center R
  pinMode(42, OUTPUT); //center W
  pinMode(44, OUTPUT); //center R
  pinMode(46, OUTPUT); //center W
  pinMode(48, OUTPUT); //center R
  pinMode(50, OUTPUT); //center W
  pinMode(52, OUTPUT); //center R
  pinMode(A1, OUTPUT); //center W
  pinMode(A2, OUTPUT); //center R
  pinMode(A3, OUTPUT); //petal 6 R
  pinMode(A4, OUTPUT); //petal 6 W
  pinMode(A5, OUTPUT); //petal 6 R
  pinMode(A6, OUTPUT); //petal 6 W
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(2, HIGH); //petal 1 W
  digitalWrite(3, HIGH);//petal 1 R
  digitalWrite(4, HIGH);//petal 1 W
  digitalWrite(5, HIGH);//petal 1 R
  digitalWrite(6, HIGH);//petal 2 R
  digitalWrite(7, HIGH);//petal 2 W
  digitalWrite(14, HIGH);//petal 2 R
  digitalWrite(15, HIGH);//petal 2 W
  digitalWrite(16, HIGH);//petal 3 R
  digitalWrite(17, HIGH);//petal 3 W
  digitalWrite(18, HIGH);//petal 3 R
  digitalWrite(19, HIGH);//petal 3 W
  digitalWrite(20, HIGH);//petal 4 W
  digitalWrite(21, HIGH);//petal 4 R
  digitalWrite(22, HIGH);//petal 4 W
  digitalWrite(24, HIGH);//petal 4 R
  digitalWrite(26, HIGH);//petal 5 R
  digitalWrite(28, HIGH);//petal 5 W
  digitalWrite(30, HIGH);//petal 5 R
  digitalWrite(32, HIGH);//petal 5 W
  digitalWrite(34, HIGH);//center W
  digitalWrite(36, HIGH);//center R
  digitalWrite(38, HIGH);//center W
  digitalWrite(40, HIGH);//center R
  digitalWrite(42, HIGH);//center W
  digitalWrite(44, HIGH);//center R
  digitalWrite(46, HIGH);//center W
  digitalWrite(48, HIGH);//center R
  digitalWrite(50, HIGH);//center W
  digitalWrite(52, HIGH);//center R
  digitalWrite(A1, HIGH);//center W
  digitalWrite(A2, HIGH);//center R
  digitalWrite(A3, HIGH);//petal 6 R
  digitalWrite(A4, HIGH);//petal 6 W
  digitalWrite(A5, HIGH);//petal 6 R
  digitalWrite(A6, HIGH);//petal 6 W
  delay(delay1);                       // wait for a second
  digitalWrite(2, LOW); 
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
    
  delay(delay2);    
  //petal 1 marquee
  digitalWrite(5, HIGH);//petal 1 R
  delay(delay3);
  digitalWrite(4, HIGH);//petal 1 W
  digitalWrite(5, LOW);//petal 1 R
  delay(delay3);
  digitalWrite(3, HIGH);//petal 1 R
  digitalWrite(4, LOW);//petal 1 W
  delay(delay3);
  digitalWrite(2, HIGH); //petal 1 W
  digitalWrite(3, LOW);//petal 1 R
  delay(delay3);
  digitalWrite(5, HIGH);//petal 1 R
  digitalWrite(2, LOW); //petal 1 W
  delay(delay3);
  digitalWrite(4, HIGH);//petal 1 W
  digitalWrite(5, LOW);//petal 1 R
  delay(delay3);
  digitalWrite(3, HIGH);//petal 1 R
  digitalWrite(4, LOW);//petal 1 W
  delay(delay3);
  digitalWrite(2, HIGH); //petal 1 W
  digitalWrite(3, LOW);//petal 1 R
  
  delay(delay3);


  
  digitalWrite(6, LOW); 
  digitalWrite(7, LOW);
  digitalWrite(14, LOW);
  digitalWrite(15, LOW);
  delay(delay4)
  //petal 2 marquee
  digitalWrite(6, HIGH);//petal 2 R
  delay(delay3);
  digitalWrite(7, HIGH);//petal 2 W
  digitalWrite(6, LOW);//petal 2 R
  delay(delay3);
  digitalWrite(14, HIGH);//petal 2 R
  digitalWrite(7, LOW);//petal 2 W
  delay(delay3);
  digitalWrite(15, HIGH);//petal 2 W
  digitalWrite(14, LOW);//petal 2 R
  delay(delay3);
  digitalWrite(6, HIGH);//petal 2 R
  digitalWrite(15, LOW);//petal 2 W
  delay(delay3);
  digitalWrite(7, HIGH);//petal 2 W
  digitalWrite(6, LOW);//petal 2 R
  delay(delay3);
  digitalWrite(14, HIGH);//petal 2 R
  digitalWrite(7, LOW);//petal 2 W
  delay(delay3);
  digitalWrite(15, HIGH);//petal 2 W
  digitalWrite(14, LOW);//petal 2 R
  delay(delay3);

  digitalWrite(16, LOW); 
  digitalWrite(17, LOW);
  digitalWrite(18, LOW);
  digitalWrite(19, LOW);
  delay(delay4)

  //petal 3 marquee
  digitalWrite(19, HIGH);//petal 3 R
  delay(delay3);
  digitalWrite(18, HIGH);//petal 3 W
  digitalWrite(19, LOW);//petal 3 R
  delay(delay3);
  digitalWrite(17, HIGH);//petal 3 R
  digitalWrite(18, LOW);//petal 3 W
  delay(delay3);
  digitalWrite(16, HIGH);//petal 3 W
  digitalWrite(17, LOW);//petal 3 W
  delay(delay3);
  digitalWrite(19, HIGH);//petal 3 R
  digitalWrite(16, LOW);//petal 3 W
  delay(delay3);
  digitalWrite(18, HIGH);//petal 3 W
  digitalWrite(19, LOW);//petal 3 R
  delay(delay3);
  digitalWrite(17, HIGH);//petal 3 R
  digitalWrite(18, LOW);//petal 3 W
  delay(delay3);
  digitalWrite(16, HIGH);//petal 3 W
  digitalWrite(17, LOW);//petal 3 W
  delay(delay3);
  digitalWrite(19, HIGH);//petal 3 R
  digitalWrite(16, LOW);//petal 3 W
  delay(delay3);


  digitalWrite(20, LOW); 
  digitalWrite(21, LOW);
  digitalWrite(22, LOW);
  digitalWrite(24, LOW);
  delay(delay4)

  //petal 4 marquee
  digitalWrite(20, HIGH);//petal 4 W
  delay(delay3);
  digitalWrite(21, HIGH);//petal 4 R
  digitalWrite(20, HIGH);//petal 4 W
  delay(delay3);
  digitalWrite(22, HIGH);//petal 4 W
  digitalWrite(21, HIGH);//petal 4 R
  delay(delay3);
  digitalWrite(24, HIGH);//petal 4 R
  digitalWrite(22, HIGH);//petal 4 W
  delay(delay3);
  digitalWrite(20, HIGH);//petal 4 W
  digitalWrite(24, HIGH);//petal 4 R
  delay(delay3);
  digitalWrite(21, HIGH);//petal 4 R
  digitalWrite(20, HIGH);//petal 4 W
  delay(delay3);
  digitalWrite(22, HIGH);//petal 4 W
  digitalWrite(21, HIGH);//petal 4 R
  delay(delay3);
  digitalWrite(24, HIGH);//petal 4 R
  digitalWrite(22, HIGH);//petal 4 W
  delay(delay3);
  digitalWrite(20, HIGH);//petal 4 W
  digitalWrite(24, HIGH);//petal 4 R
  delay(delay3);

  digitalWrite(26, LOW); 
  digitalWrite(28, LOW);
  digitalWrite(30, LOW);
  digitalWrite(32, LOW);
  delay(delay4);

    
}

Hi,

I've got a project with lots of LEDs wired in to several channels.
For example, one section has 12 circuits, each circuit is comprised of 16 LEDs.
The LEDs/circuits are in rows, wired so that one circuit hits every 4th LED.
This way I can turn on circuit 1 for say .2sec, turn it off, then turn on circuit 2, then off, etc. over and over again and it does the moving/running light look.

I've done this on other projects but it's just getting to be so cumbersome with the coding, but I'm not savvy enough to figure out any other way. which is why i'm here :slight_smile:
Basically for the coding I just use the On/Off (High/Low) commands to turn on/off each circuit in the specific order i want for the effect i'm going for.
So I usually have to create a schedule to map out every circuit, how long they need to be on/off, and in what order.
So my codes are HUGE, like 2000+ lines of just High/Low commands.
I can't find ANY other examples of projects and/or codes like mine, so I don't know if there is any better way of doing what I'm doing (if i have to change one thing it can take a long time and a lot of rewriting code).
I don't just do one series/pattern, I like to mix it up, change the on/off times, delays, channel sequencing, to do different effects.

An example of my code is below, as well as a link to a YouTube video of one of my displays and the different effects/sequencing I incorporate.
So, is there a better way to do this? or am I stuck with just a whole bunch of on/off coding in my future? Thank you!!

Oh, also, there is no multiplexing or serial comm. or anything like that going on.
These are one for one channels on the Arduino.
I use PnP Transistors as switches to source power from another power source to power all the LEDs.
So, the Arduino is just turning on/off a bunch of switches, turning on/off all the LED circuits.

Sorry but I had to edit your post to spread out your details.

You need to look up arrays.
OR
Look at Neopixels or WS2812 addressable LEDs.
They would make your wiring simpler and you do not need all those output pins.

google
neopixels ws2812

Tom... :slight_smile: