Goups of LEDs with same pattern based on condition

So, this one may be easy…but I have bashed by head off a wall for a month now and have not came up with a solution on my own.

Below is my fairly generic code. It is adapted from 3 or 4 different sources as well as some custom coding (for the fading function).

A little background on the final outcome here. I have 10 LED rings (12 LEDs each) that have an IR sensor in the middle.

The IR sensor determines the “state” (LED pattern) that each ring is in. I can code this to make each one a solid state machine, but what I want is to have all “groups” have the same pattern, as in, all rings that show an object on it display 1 LED pattern…all rings that don’t see an object, display another.

The kicker here, I want all groups of LEDs that meet a certain condition, to have the same LED pattern as the others that meet the same condition.

What I am looking to do is have the LED rings display 1 of 2 patterns, based on the readings from the IR sensor (I already have the limits and coding for this).

In summary, my generic code is below. I have a few predefined patterns designed in this code. I am looking for a hand in adding to this code so that I can have a state machine that can encompass multiple LED strings based on the reading from a sensor at each LED string.

I don’t want to beat it to death, but I want to clarify what I am looking to do. As an example. In total I have 10 LED rings. 4 of the LED rings have an IR reading that shows no object on top, 6 LED rings have an IR reading that shows an object on it. How can I group these in to 2 groups so that they update with the same pattern (i am looking for identical updates, so there is only 2 patterns displayed).

outcome:

IR sensor detects an object: have all LED rings that meet this condition to display identical pattern
IR sensor detects NO object: have all LED rings that meet this condition to display identical pattern

My code is below.

#include <Adafruit_NeoPixel.h>

#define PIN 20

Adafruit_NeoPixel Pod1 = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);

unsigned long PatternInterval = 20;
unsigned long LastUpdate = 0;

unsigned long Intervals[] = {10, 100, 20, 10, 100, 100};   //Fade, Color Wipe, Rainbow, Rainbow Cycle, Theater Chase, Rainbow Theater Chase

boolean Dimmer = false;


void setup() {

  Pod1.begin();
  Wipe(); // Initialize all pixels to 'off'
  Serial.begin(9600);
}

void loop() {
  static int Pattern = 0;
  PatternInterval = Intervals[Pattern];
  Wipe();

  if(millis() - LastUpdate > PatternInterval){
    UpdatePattern(Pattern);
  }
}

void UpdatePattern(int Pat){
  switch(Pat){
    case 0:
      Fade();
      break;
    case 1:
      ColorWipe(Pod1.Color(0,255,0));
      break;
    case 2:
      Rainbow();
      break;
    case 3:
      RainbowCycle();
      break;
    case 4:
      TheaterChase(Pod1.Color(255,0,0),Pod1.Color(0,0,255),3);
      break;
    case 5:
      RainbowTheaterChase();
      break;
    
  }
}


void Wipe(){
  for(int i=0; i<Pod1.numPixels();i++){
    Pod1.setPixelColor(i, Pod1.Color(0,0,0));
  }
}

void Fade(){
  static uint16_t j = 255;
  uint16_t i;
  if(j==50){
    Dimmer = !Dimmer;
  }
  if(j==255){
    Dimmer =!Dimmer;
  }
  if(Dimmer == false){
  if(j>50){
    for(i=0; i<Pod1.numPixels(); i++){
      Pod1.setPixelColor(i, (0,0,j));
     
    }
    Pod1.show();
   --j;
   LastUpdate = millis();
   Serial.println(j);
  }
}
if(Dimmer == true){
   if(j<255){
    for(i=0; i<Pod1.numPixels(); i++){
      Pod1.setPixelColor(i, (0,0,j));
     
   }
    Pod1.show();
    j++;
    LastUpdate = millis();
    Serial.println(j);
  }
}
}

void ColorWipe(uint32_t c) {
  static int i =0;
    Pod1.setPixelColor(i, c);
    Pod1.show();
  i++;
  if(i >= Pod1.numPixels()){
    i = 0;
    Wipe(); // blank out Pod1
  }
  LastUpdate = millis(); // time for next change to the display
}


void Rainbow() {
  static uint16_t j=0;
  uint16_t i;
    for(i=0; i<Pod1.numPixels(); i++) {
      Pod1.setPixelColor(i, Wheel((i+j) & 255));
    }
    Pod1.show();
    j++;
 if(j>=256) j=0;
 LastUpdate = millis();
  
}

void RainbowCycle() {
  static uint16_t j=0;
    for(int i=0; i< Pod1.numPixels(); i++) {
      Pod1.setPixelColor(i, Wheel(((i * 256 / Pod1.numPixels()) + j) & 255));
    }
    Pod1.show();
  j++;
  if(j >= 256*5) j=0;
  LastUpdate = millis(); // time for next change to the display
}

void TheaterChase(uint32_t c1,uint32_t c2, uint16_t space) {
   static int q = 0;
  static boolean on = true;
     if(on){
            for (uint16_t i=0; i < Pod1.numPixels(); i=i+space) {
                Pod1.setPixelColor(i+q, c1);    //turn every third pixel on
             }
     }
      else {
           for (uint16_t i=0; i < Pod1.numPixels(); i=i+space) {
               Pod1.setPixelColor(i+q, c2);        //turn every third pixel off
                 }
      }
     on = !on; // toggel pixelse on or off for next time
      Pod1.show(); // display
      q++; // update the q variable
      if(q >=space ){ // if it overflows reset it and update the J variable
        q=0;
      }
  LastUpdate = millis(); // time for next change to the display  
}

void RainbowTheaterChase() {
   static int j=0, q = 0;
  static boolean on = true;
     if(on){
            for (int i=0; i < Pod1.numPixels(); i=i+3) {
                Pod1.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
             }
     }
      else {
           for (int i=0; i < Pod1.numPixels(); i=i+3) {
               Pod1.setPixelColor(i+q, 0);        //turn every third pixel off
                 }
      }
     on = !on; // toggel pixelse on or off for next time
      Pod1.show(); // display
      q++; // update the q variable
      if(q >=3 ){ // if it overflows reset it and update the J variable
        q=0;
        j++;
        if(j >= 256) j = 0;
      }
  LastUpdate = millis(); // time for next change to the display    
}

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return Pod1.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return Pod1.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return Pod1.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

Are you planning to use one Arduino per led ring/ir sensor? Because your code only seems to deal with one. Are you asking for help expanding this code so that one Arduino controls 10 led rings and 10 ir sensors, or are you asking how to get 10 Arduino to coordinate their patterns?

I am looking to use 1 Arduino Mega to control all 10 LED rings.

I think I can use an array to control the rings, with solid state conditions to lump all like conditions together. I may have missed the mark here, but I think this idea sounds possible.

If I have 10 controllers, 1 for each ring, I can make this happen…but considering I am using this idea for a total of 20 rings…10 per side of the design…this quickly become cost inhibitive.

And to be honest, my code may be way in left field.

I am looking to have 2 distinct LED patterns…one pattern for no object on the sensor, one for an object on the sensor.

The pattern is essentially irrelevant.

The biggest thing is to have like patterns running at the identical position…regardless of when it was triggered.

In my mind I see 2 arrays. 1 array that displays a pattern that does not meet a condition…one array that displays a pattern that meets a condition.

As in, If an object is detected, all LED rings that meet his condition will display an identical pattern…same for all LED rings that have no object on then.

Right, I think I understand what you want to do. But I don't understand why you "bashed by head off a wall for a month". Have you tried getting it to work with two led rings and two ir sensors? What happened? Can you post your attempt at that code.