Triggering 4 NeoPixel LED strips - function code question

Hey all, I’m relatively new to Arduino and coding so hopefully I’m able to accurately explain what I’m trying to accomplish here…

I have 4 Adafruit NeoPixel RGBW strips that I’d like to trigger on/off with piezo sensors… I’ve got the triggering part of it figured out, but I’m trying to optimize my code structure down to as little as possible. I’m having trouble figuring out how to pass variables down to new functions without having to write a bunch of Switch/Case code to control the 4 different LED strips, along with different colors and animations.

My flow chart:

  1. Detect a vibration trigger from one (or more, at any given time) piezo sensors (4 sensors total) →

(go to a fireTRIG() function that would then…)

  1. Pull RGBW color values from a color array to send to the RGBW strip (or strips) being triggered →

  2. Pull an animation mode from a global variable (animation modes would be for example: 0 = flash on/off, 1 = strobe, 2= fade down, etc). Each RGBW strip would have its own global variable for it’s current animation mode

  3. The fireTRIG function would need to determine 3 variables: channel(s) being tiggered, color, & hold, and then pass those variables down to other functions (MODES/ANIMATION STYLES) that make the NeoPixels turn on/off/animate.

I’m having a problem sending the channel variable to my various animation code functions that make the NeoPixel strip(s) do their thing. For example here is my flash on/off function:

void modeFlash(uint32_t channel, uint32_t color, uint32_t hold) {
for (int i = 0; i < 13; i = i + 1) {
CH1_STRIP.setPixelColor(i, color);
}

CH1_STRIP.show();
delay(hold);
}

Notice the parts in red. I’ve figured out how to pass the color & hold(ms delay) times down to this function from the previous fireTRIG() function I’ve written. So my question is, how can I get the CH1_STRIP part to change without having to write a bunch of Switch/Case code? I included the uint32_t channel parameter, but I can’t figure out how to make that change to control the NeoPixel .setPixelColor() and .show() functions…so I’m basically trying to make it do this:

void modeFlash(uint32_t channel, uint32_t color, uint32_t hold) {
for (int i = 0; i < 13; i = i + 1) {
INSERT CHANNEL PARAMETER FROM ABOVE.setPixelColor(i, color);
}

INSERT CHANNEL PARAMETER FROM ABOVE.show();
delay(hold);
}

Here is my full code for context:

#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel CH1_STRIP = Adafruit_NeoPixel(13, 6, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel CH2_STRIP = Adafruit_NeoPixel(20, 7, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel CH3_STRIP = Adafruit_NeoPixel(13, 8, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel CH4_STRIP = Adafruit_NeoPixel(13, 9, NEO_GRBW + NEO_KHZ800);

//For piezo sensors
#define TRIG_1 A1
#define TRIG_2 A2
#define TRIG_3 A3
#define TRIG_4 A4
int TRIG_1_READING = 0;
int TRIG_2_READING = 0;
int TRIG_3_READING = 0;
int TRIG_4_READING = 0;

//global color, animation mode, and hold(time) variables:
//NOTE: I'm planning on storing all of these variables in an array later

int CH1_currentCOLOR = 1; //from colorArray below
int CH1_currentMODE = 0; //animation mode number. modeFlash (mode 0) funtion included below
int CH1_currentHOLD = 200; //How long (in ms) the RGBW strip stays on before turing off

int CH2_currentCOLOR = 4;
int CH2_currentMODE = 0;
int CH2_currentHOLD = 200;

int CH3_currentCOLOR = 7;
int CH3_currentMODE = 0;
int CH3_currentHOLD = 200;

int CH4_currentCOLOR = 5;
int CH4_currentMODE = 0;
int CH4_currentHOLD = 200;

int colorArray[][4] = 
{
  {255, 0, 0, 0}, //red 0
  {255, 50, 0, 0}, //orange 1
  {150, 100, 0, 0}, //yellow 2
  {0, 255, 0, 0}, //green 3
  {0, 0, 255, 0}, //blue 4
  {255, 0, 255, 0}, //purple 5
  {255, 20, 50, 0}, //pink 6
  {0, 0, 0, 255} //white 7
};

void setup() {
  Serial.begin(9600);

  pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
      pinMode(8, OUTPUT);
        pinMode(9, OUTPUT);
  pinMode(TRIG_1, INPUT);
    pinMode(TRIG_2, INPUT);
      pinMode(TRIG_3, INPUT);
        pinMode(TRIG_4, INPUT);

    //for the NeoPixel strips
  CH1_STRIP.begin(); CH1_STRIP.setBrightness(50); CH1_STRIP.show();
    CH2_STRIP.begin(); CH2_STRIP.setBrightness(50); CH2_STRIP.show();
      CH3_STRIP.begin(); CH3_STRIP.setBrightness(50); CH3_STRIP.show();
        CH4_STRIP.begin(); CH4_STRIP.setBrightness(50); CH4_STRIP.show();
}

void loop() {

  //read values from piezo sensors
  //if they are above the threshold level (300), go to the fireTRIG function
    TRIG_1_READING = analogRead(TRIG_1);
    if(TRIG_1_READING >= 300) {
      fireTRIG ();
    }
        TRIG_2_READING = analogRead(TRIG_2);
    if(TRIG_2_READING >= 300) {
      fireTRIG ();
    }
        TRIG_3_READING = analogRead(TRIG_3);
    if(TRIG_3_READING >= 300) {
      fireTRIG ();
    }
        TRIG_4_READING = analogRead(TRIG_4);
    if(TRIG_4_READING >= 300) {
      fireTRIG ();
    }


    //CLEAR STRIPS if they are not being triggered
    int i;
    for (i = 0; i < 13; i = i + 1) {
    CH1_STRIP.setPixelColor(i, 0, 0, 0, 0);
  }
  //ETC to do the same for the other 3 strips...

    CH1_STRIP.show(); //and the same for the other 3 strips here...

}

void fireTRIG ()
{
  //pull the RGBW values for CH1 from the colorArray with this for loop
  int CH1_getColor[4];
  for(int i = 0; i < 4; i++) {
    CH1_getColor[i] = colorArray[CH1_currentCOLOR][i];
    }
    //repeat the same for loop for the other 3 strips to gather color information

    //depending on which of the 4 piezo sensors are being triggered,
    //this next line of code would send channel, color, and hold information
    //down to the modeFlash animation

        modeFlash([color=red]CURRENT CHANNEL BEING TIGGERED[/color], (CH1_getColor[0], CH1_getColor[1], CH1_getColor[2], CH1_getColor[3]), CH1_currentHOLD);
}

void modeFlash(uint32_t channel ([color=red]CURRENT CHANNEL BEING TIGGERED[/color]), uint32_t color, uint32_t hold) {
      for (int i = 0; i < 13; i = i + 1) {
      CH1_STRIP ([color=red]should be CURRENT CHANNEL BEING TIGGERED[/color]).setPixelColor(i, color);
      }
      
        CH1_STRIP ([color=red]should be CURRENT CHANNEL BEING TIGGERED[/color]).show();
        delay(hold);
}

You could have all the different channels in an array and then you could use your integer as an index to that array to pick the right one.

Or you could make your function take a parameter of type Adafruit_Neopixel instead of uint32_t and pass the channel directly to the function.