Spectrum Analyzer using Adafruit NeoPixel Strips & Arduino Mega

Hello everyone,

I wanted to created a separate thread to address an issue. I've created a successful LED audio spectrum analyzer using Adafruit Neopixel Strips, Arduino Mega, 2 MSGEQ7 Chips (One for the Left Audio Channel and the other for the right), and an audio jack.

I am at that point in my project where I would like to add extra things if I could. I want to add a push button feature where I can cycle through different colors at a push of a button. I'm currently working on the code (which I'm having trouble with), but that's not the real problem.

See attached PDF "Led Audio Spectrum Analyzer 14 Band" for a circuit schematic I've created. I also have a picture of my circuit in the attachments for reference as well. Anyways...I attached my push button to my breadboard and attached 5VDC to one side of the push button and then attached a 10K resistor to the other side going to ground. Then I added a wire from Arduino Digital Pin 30 to the push button. I knew it was working correctly since the ButtonCycler code that Adafruit provides in their library worked correctly.

I then uploaded my current code for my spectrum analyzer while playing music for a second and noticed that the left channel LEDs were not moving (FYI, I still had my push button integrated in my breadboard. No code done yet). At first I thought it was a coding issue, but in my mind it had to be something with the button I integrated in my breadboard.

I then figured out that if I removed my 5VDC wire from the push button, the left channel started to work again (after I pulled out my MSGEQ7 Left hand chip and put it back into the board). These chips receive 5VDC at Pin 1 so I'm not sure if adding a new path to push button should be causing these issues for the MSGEQ7 not to work.

Does anyone have any idea on what I should do or test? Maybe I should check the voltage at Pin 1 and ground for the MSGEQ7 chip but I feel like I shouldn't have a huge voltage drop just because I installed a small push button.

Sorry for the lengthy post. Trying to be detailed.

Thanks in advance,
Eddie

P.S.
The picture I attached does not show the push button integrated in the board. Ignore the random capacitor in the front. I forgot to remove it when taking this picture.

LED Audio Spectrum Analyzer 14 Band (09-21-2017).pdf (48 KB)


....

Mike,

I got it to work.

#include <MSGEQ7.h>
 
#include <Adafruit_NeoPixel.h>
//#define A0
//#define A1
#define pinReset 27
#define pinStrobe 26
#define BRIGHTNESS 50
 
#define LEDs 280 //total number of LEDs
#define PIN 22
#define BUTTON_PIN 30
 
#define OffColor 0x000000    // OFF
int SpectrumLeft[7];
int SpectrumRight[7];
 
int red[20];
int green[20];
int blue[20];
 
int red_rainbow[20] = {91,255,127,0,0,0,0,0,0,0,0,0,64,127,191,255,255,255,255,189};
int green_rainbow[20] = {2,0,0,0,64,127,191,255,255,255,255,255,255,255,255,255,191,0,0,0};
int blue_rainbow[20] = {47,255,255,255,255,255,255,255,191,127,64,0,0,0,0,0,0,0,0,0};
 
int j;

int SpectrumGraphLeft[7][20];
int SpectrumGraphRight[7][20];
 
Adafruit_NeoPixel Strip = Adafruit_NeoPixel(LEDs, PIN, NEO_GRB + NEO_KHZ800);
 
//#define MSGEQ7_INTERVAL ReadsPerSecond(50)
//#define MSGEQ7_SMOOTH 191 // Range: 0-255
 
//CMSGEQ7<MSGEQ7_SMOOTH, pinReset, pinStrobe, pinAnalogleft> MSGEQ7;
 
// Choose a PWM pin!
#define pinLed 22
 
bool oldState = HIGH;
int showType = 0;
 
void setup()
{
 
Serial.begin(9600);
Strip.setBrightness(BRIGHTNESS);
 
 
//pinMode(pinAnalogleft, INPUT);
pinMode(pinStrobe, OUTPUT);
pinMode(pinReset, OUTPUT);
//analogReference(DEFAULT);
 
digitalWrite(pinStrobe,LOW);
digitalWrite(pinReset,HIGH);
digitalWrite(pinStrobe,HIGH);
digitalWrite(pinStrobe,LOW);  //Strobe pin on the shield (go to next Band)
digitalWrite(pinReset,LOW);
 
// Assign pixels to graph array
  for (byte bar = 0 ; bar < 7 ; bar++)
 
  {
                if ( bar == 0)             
                {
    for (byte pixel = 0 ; pixel < 20 ; pixel ++)
              
    {
      SpectrumGraphLeft[bar][pixel] = (bar * 20) + pixel;
      SpectrumGraphRight[bar][pixel] = (-1*pixel)+279;
    }    // end for
                }
                else if ( bar == 1) //flipped strip
                {
                for (byte pixel = 0 ; pixel < 20  ; pixel ++)
    {
      SpectrumGraphLeft[bar][pixel] = (-1*pixel)+39;
      SpectrumGraphRight[bar][pixel] = (pixel)+240;
    }    // end for
                }
                 else if (bar ==2)
                {
                for (byte pixel = 0 ; pixel < 20 ; pixel ++)
    {
      SpectrumGraphLeft[bar][pixel] = ((bar) * 20) + pixel;
      SpectrumGraphRight[bar][pixel] = (-1*pixel)+239;
     
    }    // end for
     }
                 else if (bar == 3) //flipped strip
                {
                 for (byte pixel = 0 ; pixel < 20  ; pixel ++)
    {
      SpectrumGraphLeft[bar][pixel] = (-1*pixel)+79;
      SpectrumGraphRight[bar][pixel] = (pixel)+200;
    }    // end for
                }
                else if (bar == 4)
                {
                  for (byte pixel = 0 ; pixel < 20  ; pixel ++)
    {
      
      SpectrumGraphLeft[bar][pixel] = ((bar) * 20) + pixel; 
      SpectrumGraphRight[bar][pixel] = (-1*pixel)+199;  
        }    // end for         
                }
 
                else if  (bar == 5)
                {
                  for (byte pixel = 0 ; pixel < 20  ; pixel ++)
    {
      SpectrumGraphLeft[bar][pixel] = (-1*pixel)+119;
      SpectrumGraphRight[bar][pixel] = (pixel)+160;   
        }    // end for         
                }
                else if  (bar == 6)
                {
                  for (byte pixel = 0 ; pixel < 20  ; pixel ++)
    {
      SpectrumGraphLeft[bar][pixel] = ((bar) * 20) + pixel;
      SpectrumGraphRight[bar][pixel] = (-1*pixel)+159;   
        }    // end for         
                }   
  } // end for
 
pinMode(BUTTON_PIN, INPUT_PULLUP); 
Strip.begin();
Strip.show(); // Initialize all pixels to 'off'
 
}

void startShow(int i) {
  switch(i){
   
    case 1: // Rainbow
  for (j=0; j<20; j++)
    {
    red[j] = red_rainbow[j];
    green[j] = green_rainbow[j];
    blue[j] = blue_rainbow[j];
    }
 
   mapSpectrum();
            break;
    
    
    case 2:  //Red
    for (j=0; j<20; j++)
    {
    red[j] = 225;
    green[j] = 0;
    blue[j] = 0;
    }
    mapSpectrum();   
            break;
           
  case 3:  //Blue
    for (j=0; j<20; j++)
    {
    red[j] = 0;
    green[j] = 0;
    blue[j] = 225;
    }
    mapSpectrum();   
            break;
           
       
    case 4:  //Green
    for (j=0; j<20; j++)
    {
    red[j] = 0;
    green[j] = 225;
    blue[j] = 0;
    }
    mapSpectrum();   
            break; 
}
} 
 
void loop()
{
 
  Serial.print(SpectrumGraphLeft[7][20]);
  Serial.print(SpectrumGraphRight[7][20]);
  readSpectrum();      // Get values from spectrum shield
  mapSpectrum();      // Color pixels according to spectrum values   
  
   
 // delay(15);
 
  // Get current button state.
  bool newState = digitalRead(BUTTON_PIN);
 
  // Check if state changed from high to low (button press).
  if (newState == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      showType++;
      if (showType > 4)
        showType=1;
      startShow(showType);
    }
   
  }
// Set the last button state to the old state.
  oldState = newState;
 
}
 

void readSpectrum()
{
  // Band 0 = Lowest Frequencies.
  byte Band;
  for(Band=0;Band <7; Band++)
  {
    SpectrumLeft[Band] = analogRead(A0); //left
    SpectrumRight[Band] = analogRead(A1); //right
   
    digitalWrite(pinStrobe,HIGH);
    digitalWrite(pinStrobe,LOW);
    //delayMicroseconds(50);
 
      }
   
    
}
 
 
 
 

 
 
void mapSpectrum()    // map spectrum to pixel strips
{
  for(byte Band=0 ; Band <7 ; Band++)
  {    
    SpectrumLeft[Band] = map(SpectrumLeft[Band],100 , 800, 0, 19);
    SpectrumRight[Band] = map(SpectrumRight[Band], 45, 800, 0, 19);
  
  for(int Pixel = 0; Pixel < SpectrumLeft[Band]; Pixel++){
    Strip.setPixelColor(SpectrumGraphLeft[Band][Pixel], red[Pixel],green[Pixel],blue[Pixel]);
}
                for (byte Pixel = SpectrumLeft[Band] ; Pixel < 20 ; Pixel++)
                                {      // Turn the rest OFF!
                                               Strip.setPixelColor(SpectrumGraphLeft[Band][Pixel], OffColor);
                                }    // end for (Pixel
 
   for(int Pixel = 0; Pixel < SpectrumRight[Band]; Pixel++){
    Strip.setPixelColor(SpectrumGraphRight[Band][Pixel], red[Pixel],green[Pixel],blue[Pixel]);
}
                for (byte Pixel = SpectrumRight[Band] ; Pixel < 20 ; Pixel++)
                                {      // Turn the rest OFF!
                                               Strip.setPixelColor(SpectrumGraphRight[Band][Pixel], OffColor);
                                }    // end for (Pixel
                          
 
  }    // end for (Band

  Strip.show();
   
 
 
 
}

Had one question:

  1. I noticed that previous color settings leak into existing color. For example, Case 4 shows the LEDs as being green, but I tend to see Blue flicker randomly in some LEDs. What might be causing this?

Thanks,
Eddie

Edcastillo09:
I attached my push button to my breadboard and attached 5VDC to one side of the push button and then attached a 10K resistor to the other side going to ground.

Much easier (and safer) to connect the button between an input pin and ground. No resistor.
And enable the internal pull up resistor with code.

pinMode(buttonPin, INPUT_PULLUP);

Inverted logic now.
A HIGH is not pushed, and a LOW is pushed.
Leo..

Wawa:
Much easier (and safer) to connect the button between an input pin and ground. No resistor.
And enable the internal pull up resistor with code.

pinMode(buttonPin, INPUT_PULLUP);

Inverted logic now.
A HIGH is not pushed, and a LOW is pushed.
Leo..

Hi Leo,

Your pinMode code is exactly what I have in my code. I actually took off the resistor and moved my wire from 5VDC to ground so I can have the same configuration you mentioned for my push button. The weird thing is that when I did that, I lost my left hand LEDs as if the MSGEQ7 chip was pulled out of my circuit. Not sure why but messing with the power rails affects this chip... weird.

Edcastillo09:
The weird thing is that when I did that, I lost my left hand LEDs as if the MSGEQ7 chip was pulled out of my circuit. Not sure why but messing with the power rails affects this chip... weird.

Must be in the code then.
Not very clever to spread problems for the same project across several threads.
Leo..

Wawa:
Must be in the code then.
Not very clever to spread problems for the same project across several threads.
Leo..

I'll stop responding in here then. Wonder if a moderator can delete this

The moderators can merge the thread for you. Click "report to moderator" and ask for that, giving a link to your other thread.

Threads merged as requested.

@Edcastillo09, thank you for doing the right thing. Karma to you.

Thank you Coding Badly! I wasn't thinking at the time. This thread has so much information that combing things will help. I hope this thread helps someone else in the near or far future. All this learning excites me and causes me to become impatient sometimes :slight_smile:

Trying to be smart and clean up my code. But I'm having some array issues.

My main question is can you store multiple integers in one array index? For example, I am trying to set a color to each LED in its band. I have 7 bands on the left and 7 bands on the right and each band contains 20 LEDs. I did not want to create a [7][20] array due to it taking up so much space so I did the following:

int color_rainbow[1][20] =
{(91,2,47),  (255,0,255),  (127,0,255),  (0,0,255),  (0,64,255), (0,127,255),  (0,191,255),  (0,255,255),  (0,255,191),  (0,255,127),  (0,255,64), (0,255,0),  (64,255,0), (127,255,0),  (191,255,0),  (255,255,0),  (255,191,0),  (255,0,0),  (255,0,0),  (189,0,0)};

For my push button case, I did the following:

 case 1: // Rainbow
  for (k=0; k<7; k++)
     {   
    for (j=0; j<20; j++)
    {
    color[k][j] = color_rainbow[1][j];
    }
    }
    mapSpectrum(); 
            break;

Then I made this my mapSpectrum so it can place each LED HTML Color code in it's appropriate place.

void mapSpectrum()    // map spectrum to pixel strips
{
  for(byte Band=0 ; Band <7 ; Band++)
  {   
    SpectrumLeft[Band] = map(SpectrumLeft[Band],100 , 800, 0, 19);
    SpectrumRight[Band] = map(SpectrumRight[Band], 45, 800, 0, 19);
 
  for(int Pixel = 0; Pixel < SpectrumLeft[Band]; Pixel++){
    Strip.setPixelColor(SpectrumGraphLeft[Band][Pixel], color[Band][Pixel]);
}
                for (byte Pixel = SpectrumLeft[Band] ; Pixel < 20 ; Pixel++)
                                {      // Turn the rest OFF!
                                               Strip.setPixelColor(SpectrumGraphLeft[Band][Pixel], OffColor);
                                }    // end for (Pixel
   for(int Pixel = 0; Pixel < SpectrumRight[Band]; Pixel++){
    Strip.setPixelColor(SpectrumGraphRight[Band][Pixel], color[Band][Pixel]);
}
                for (byte Pixel = SpectrumRight[Band] ; Pixel < 20 ; Pixel++)
                                {      // Turn the rest OFF!
                                               Strip.setPixelColor(SpectrumGraphRight[Band][Pixel], OffColor);
                                }    // end for (Pixel
                        
  }    // end for (Band
  Strip.show(); 
}

I know why it doesn't work. It does like the fact I'm storing multiple numbers in one array index. And it doesnt like the parentheses. How can I fix my array? Or do I have to just initialize a whole [7][20] array? I could you HEX codes for the colors but that's a pain.

The reason I want to do this is so I don't have to create another mapSpectrum. I want to 1. set different colors to each LED in a band and repeat it for all the rest of the bands, and 2. I want to set one color to each band.

Thanks,
Eddie

A struct would go nicely with what you are trying to do...

typedef struct
{
  byte              r;
  byte              g;
  byte              b;
}
rgb_t;

rgb_t color_rainbow[20] =
{{91,2,47},  {255,0,255},  {127,0,255},  {0,0,255},  {0,64,255}, {0,127,255},  {0,191,255},  {0,255,255},  {0,255,191},  {0,255,127},  {0,255,64}, {0,255,0},  {64,255,0}, {127,255,0},  {191,255,0},  {255,255,0},  {255,191,0},  {255,0,0},  {255,0,0},  {189,0,0}};

#define NUMBEROF(a) (sizeof(a)/sizeof(a[0]))

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

  for ( int i=0; i < NUMBEROF(color_rainbow); ++i )
  {
    Serial.print( F( " #" ) );
    Serial.print( i );
    Serial.print( F( "  " ) );
    Serial.print( F( "r:" ) );
    Serial.print( color_rainbow[i].r );
    Serial.print( F( "  " ) );
    Serial.print( F( "g:" ) );
    Serial.print( color_rainbow[i].g );
    Serial.print( F( "  " ) );
    Serial.print( F( "b:" ) );
    Serial.print( color_rainbow[i].b );
    Serial.println();
  }
}

void loop() { }

Thank you for your reply Coding...I'd have to learn about this and play with it in the morning. Just something i noticed though. If im making the operator for color_rainbow as rgb_t then wouldn't my case 0 code fail because due to color[k][j] having the operator as int ? the operators won't match here:

color[k][j] = color_rainbow[1][j];

;

Thanks,
Eddie

You did not include the datatype for color so I have no idea what change is needed.

Sorry that I wasn't being clear. My apologies. I think posting my code might help. See below:

#include <MSGEQ7.h>
#include <Adafruit_NeoPixel.h>
#define pinReset 27
#define pinStrobe 26
#define BRIGHTNESS 50
#define LEDs 280 //total number of LEDs
#define PIN 22
#define BUTTON_PIN 28
#define OffColor 0x000000    // OFF
Adafruit_NeoPixel Strip = Adafruit_NeoPixel(LEDs, PIN, NEO_GRB + NEO_KHZ800);
 

int SpectrumLeft[7];
int SpectrumRight[7];
int SpectrumGraphLeft[7][20];
int SpectrumGraphRight[7][20];

int color[7][20]; //used in mapSpectrum  cases 4-6

//used in cases 1-3

int color_rainbow[1][20] = 
{(91,2,47),  (255,0,255),  (127,0,255),  (0,0,255),  (0,64,255), (0,127,255),  (0,191,255),  (0,255,255),  (0,255,191),  (0,255,127),  (0,255,64), (0,255,0),  (64,255,0), (127,255,0),  (191,255,0),  (255,255,0),  (255,191,0),  (255,0,0),  (255,0,0),  (189,0,0)};
int color_warm[1][20] = 
{(206,36,36),  (206,36,36),  (206,36,36),  (255,0,50),  (255,0,50), (255,0,50),  (206,132,36),  (206,132,36),  (206,132,36),  (255,165,0),  (255,165,0), (255,165,0),  (255,205,0), (255,205,0),  (255,205,0),  (255,255,0),  (255,255,0),  (255,255,0),  (255,255,0),  (255,255,0)};
int color_cool[1][20] =
{(238,130,238),  (238,130,238),  (238,130,238),  (238,130,238),  (238,130,238), (138,43,226),  (138,43,226),  (138,43,226),  (138,43,226),  (138,43,226),  (100,0,255), (100,0,255),  (100,0,255), (100,0,255),  (100,0,255),  (0,255,255),  (0,255,255),  (0,255,255),  (0,255,255),  (0,255,255)};
int color_vertical[7][1]=
{{(128,0,128)},{(0,0,255)},{(0,255,255)},{(0,255,0)},{(255,255,0)},{(255,165,0)},{(255,0,0)}};

int j;
int k; 

bool oldState = HIGH;
int showType = 0;

void setup()
{
Serial.begin(9600);
Strip.setBrightness(BRIGHTNESS);
pinMode(pinStrobe, OUTPUT);
pinMode(pinReset, OUTPUT);
digitalWrite(pinStrobe,LOW);
digitalWrite(pinReset,HIGH);
digitalWrite(pinStrobe,HIGH);
digitalWrite(pinStrobe,LOW);  //Strobe pin on the shield (go to next Band)
digitalWrite(pinReset,LOW);

// Assign pixels to graph array
for (byte bar = 0 ; bar < 7 ; bar = bar+2)
  {
    for (byte pixel = 0 ; pixel < 20 ; pixel ++)
             
    {
      SpectrumGraphLeft[bar][pixel] = (bar * 20) + pixel;
      SpectrumGraphRight[bar][pixel] = 279 - ((bar * 20) + pixel);
    }    // end for
                }
       
for (byte bar = 1 ; bar < 7 ; bar = bar+2)
  {
    for (byte pixel = 0 ; pixel < 20 ; pixel ++)
             
    {
      SpectrumGraphLeft[bar][pixel] = ((bar+1)*20)-(1+pixel);
      SpectrumGraphRight[bar][pixel] = ((13-bar)*20)+pixel;
    }    // end for
                }
 
pinMode(BUTTON_PIN, INPUT_PULLUP);
Strip.begin();
Strip.show(); // Initialize all pixels to 'off'
}
 
void startShow(int i) {
  switch(i){
  case 1: // Rainbow
  for (k=0; k<7; k++)
     {   
    for (j=0; j<20; j++)
    {
    color[k][j] = color_rainbow[1][j];
    }
    }
    mapSpectrum(); 
            break;
 
  case 2: // Warm
  for (k=0; k<7; k++)
     {   
    for (j=0; j<20; j++)
    {
    color[k][j] = color_warm[1][j];
    }
    }
    mapSpectrum(); 
            break;
 
   case 3: // Cool
   for (k=0; k<7; k++)
     {   
    for (j=0; j<20; j++)
    {
    color[k][j] = color_cool[1][j];
    }
    }
    mapSpectrum(); 
            break;              
 
   case 4: // Vertical
   for (k=0; k<7; k++)
     {   
    for (j=0; j<20; j++)
    {
    color[k][j] = color_vertical[k][1];
    }
    }
    mapSpectrum(); 
            break; 
    
   case 5:  //Red
   for (k=0; k<7; k++)
     {   
    for (j=0; j<20; j++)
    {
    color[k][j] = 255,0,0;
    }
    }
    mapSpectrum(); 
            break;
         
   case 6:  //Green
   for (k=0; k<7; k++)
     {   
    for (j=0; j<20; j++)
    {
    color[k][j] = 0,0,255;
    }
    }
    mapSpectrum(); 
            break;
            
   case 7:  //Blue
   for (k=0; k<7; k++)
     {   
    for (j=0; j<20; j++)
    {
    color[k][j] = 0,0,255;
    }
    }
    mapSpectrum(); 
            break;
}
}
void loop()
{
  Serial.print(SpectrumGraphLeft[7][20]);
  Serial.print(SpectrumGraphRight[7][20]);
  readSpectrum();      // Get values from spectrum shield
  mapSpectrum();      // Color pixels according to spectrum values 
  delay(15);
  // Get current button state.
  bool newState = digitalRead(BUTTON_PIN);
  // Check if state changed from high to low (button press).
  if (newState == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      showType++;
      if (showType > 7)
        showType=1;
      startShow(showType);
    }
  }
// Set the last button state to the old state.
  oldState = newState;
  
  
}
void readSpectrum()
{
  // Band 0 = Lowest Frequencies.
  byte Band;
  for(Band=0;Band <7; Band++)
  {
    SpectrumLeft[Band] = analogRead(A0); //left
    SpectrumRight[Band] = analogRead(A1); //right
    digitalWrite(pinStrobe,HIGH);
    digitalWrite(pinStrobe,LOW);
    //delayMicroseconds(50);
       }
}
void mapSpectrum()    // map spectrum to pixel strips
{
  for(byte Band=0 ; Band <7 ; Band++)
  {   
    SpectrumLeft[Band] = map(SpectrumLeft[Band],100 , 800, 0, 19);
    SpectrumRight[Band] = map(SpectrumRight[Band], 45, 800, 0, 19);
 
  for(int Pixel = 0; Pixel < SpectrumLeft[Band]; Pixel++){
    Strip.setPixelColor(SpectrumGraphLeft[Band][Pixel], color[Band][Pixel]);
}
                for (byte Pixel = SpectrumLeft[Band] ; Pixel < 20 ; Pixel++)
                                {      // Turn the rest OFF!
                                               Strip.setPixelColor(SpectrumGraphLeft[Band][Pixel], OffColor);
                                }    // end for (Pixel
   for(int Pixel = 0; Pixel < SpectrumRight[Band]; Pixel++){
    Strip.setPixelColor(SpectrumGraphRight[Band][Pixel], color[Band][Pixel]);
}
                for (byte Pixel = SpectrumRight[Band] ; Pixel < 20 ; Pixel++)
                                {      // Turn the rest OFF!
                                               Strip.setPixelColor(SpectrumGraphRight[Band][Pixel], OffColor);
                                }    // end for (Pixel
                        
  }    // end for (Band
  Strip.show(); 
}

Does that code compile?

Yes it's does but I'm sure it doesn't like the way I set up my array. I don't think I can have an array index of "(r,g,b)" where r,g,b are the values. I'm going to put HMTL Hex color codes instead so I won't have multiple values in an array index.

I think my for loops in my void startshow are incorrect. I'm pretty much trying to create the [7][20] in my for loops instead of at the beginning so when it starts pulling values for color[Band][Pixel] in my mapSpectrum it will give the correct color to each pixel it's in band. Then repeat for each band.

Sorry if that's confusing. If you want me to I can show you in an excel sheet the [7][20] array I want to create with my for loops.

I could you HEX codes for the colors but that's a pain.

As your code stands you are currently mixing the two methods. You are storing separate RGB values then passing just one of those values in the calls to setPixelColor. (You need to learn how the comma operator works.) Pick one method and use it consistently.

Coding Badly,

I looked into the comma operator, but I'm not sure how I can use that to my benefit for assigning one color to each band.

I'd like to assign the colors like the following:

I decided I am going to stick with the r,g,b values for my map spectrum. It just works better. I want to add another case for assigning one color per band, but I can't figure this out with modifying my mapSpectrum(). Is there any way to do it? :frowning: See current code below:

#include <MSGEQ7.h>
#include <Adafruit_NeoPixel.h>
#define pinReset 27
#define pinStrobe 26
#define BRIGHTNESS 65
#define LEDs 280 //total number of LEDs
#define PIN 22
#define BUTTON_PIN 28
#define OffColor 0x000000    // OFF
Adafruit_NeoPixel Strip = Adafruit_NeoPixel(LEDs, PIN, NEO_GRB + NEO_KHZ800);

int SpectrumLeft[7];
int SpectrumRight[7];
int red[20];
int green[20];
int blue[20];
int color[7][20];  
int red_rainbow[20] = {91,255,127,0,0,0,0,0,0,0,0,0,64,127,191,255,255,255,255,189};
int green_rainbow[20] = {2,0,0,0,64,127,191,255,255,255,255,255,255,255,255,255,191,0,0,0};
int blue_rainbow[20] = {47,255,255,255,255,255,255,255,191,127,64,0,0,0,0,0,0,0,0,0};
int red_warm[20] = {206,206,206,255,255,255,206,206,206,255,255,255,255,255,255,255,255,255,255,255};
int green_warm[20] = {36,36,36,0,0,0,132,132,132,165,165,165,205,205,205,255,255,255,255,255};
int blue_warm[20] = {36,36,36,50,50,50,36,36,36,0,0,0,0,0,0,0,0,0,0,0};
int red_cool[20] = {238,238,238,238,238,138,138,138,138,138,100,100,100,100,100,0,0,0,0,0};
int green_cool[20] = {130,130,130,130,130,43,43,43,43,43,0,0,0,0,0,255,255,255,255,255};
int blue_cool[20] = {238,238,238,238,238,226,226,226,226,226,255,255,255,255,255,255,255,255,255,255};
int red_flame[20] = {0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255};
int green_flame[20] = {0,0,0,0,0,0,100,100,100,255,255,255,255,255,255,255,255,120,120,120};
int blue_flame[20] = {255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int j;
int SpectrumGraphLeft[7][20];
int SpectrumGraphRight[7][20];
bool oldState = HIGH;
int showType = 0;
 
void setup()
{
 
Serial.begin(9600);
Strip.setBrightness(BRIGHTNESS);
pinMode(pinStrobe, OUTPUT);
pinMode(pinReset, OUTPUT);
digitalWrite(pinStrobe,LOW);
digitalWrite(pinReset,HIGH);
digitalWrite(pinStrobe,HIGH);
digitalWrite(pinStrobe,LOW);  //Strobe pin on the shield (go to next Band)
digitalWrite(pinReset,LOW);
 
// Assign pixels to graph array
for (byte bar = 0 ; bar < 7 ; bar = bar+2)
  {
    for (byte pixel = 0 ; pixel < 20 ; pixel ++)       
    {
      SpectrumGraphLeft[bar][pixel] = (bar * 20) + pixel;
      SpectrumGraphRight[bar][pixel] = 279 - ((bar * 20) + pixel);
    }    // end for
                }
       
for (byte bar = 1 ; bar < 7 ; bar = bar+2)
  {
    for (byte pixel = 0 ; pixel < 20 ; pixel ++)        
    {
      SpectrumGraphLeft[bar][pixel] = ((bar+1)*20)-(1+pixel);
      SpectrumGraphRight[bar][pixel] = ((13-bar)*20)+pixel;
    }    // end for
                }
 
pinMode(BUTTON_PIN, INPUT_PULLUP); 
Strip.begin();
Strip.show(); // Initialize all pixels to 'off'
}

void startShow(int i) {
  switch(i){
   
    case 1: // Rainbow
  for (j=0; j<20; j++)
    {
    red[j] = red_rainbow[j];
    green[j] = green_rainbow[j];
    blue[j] = blue_rainbow[j];
    }
   mapSpectrum();
            break;

    case 2: // Warm
  for (j=0; j<20; j++)
    {
    red[j] = red_warm[j];
    green[j] = green_warm[j];
    blue[j] = blue_warm[j];
    }
    mapSpectrum();
            break;

      case 3: // Cool
  for (j=0; j<20; j++)
    {
    red[j] = red_cool[j];
    green[j] = green_cool[j];
    blue[j] = blue_cool[j];
    }
    mapSpectrum();
            break;    
               
     case 4: // Flame
  for (j=0; j<20; j++)
    {
    red[j] = red_flame[j];
    green[j] = green_flame[j];
    blue[j] = blue_flame[j];
    }
    mapSpectrum();
            break; 
            
    case 5:  //Red
    for (j=0; j<20; j++)
    {
    red[j] = 225;
    green[j] = 0;
    blue[j] = 0;
    }
    mapSpectrum();   
            break;
           
  case 6:  //Blue
    for (j=0; j<20; j++)
    {
    red[j] = 0;
    green[j] = 0;
    blue[j] = 225;
    }
    mapSpectrum();   
            break;    
            
   case 7:  //Green
    for (j=0; j<20; j++)
    {
    red[j] = 0;
    green[j] = 255;
    blue[j] =0;
    }
    mapSpectrum();   
            break;   
            
    default:
      //if nothing else matches, do the default
            break;
}
} 
 
void loop()
{ 
  Serial.print(SpectrumGraphLeft[7][20]);
  Serial.print(SpectrumGraphRight[7][20]);
  readSpectrum();      // Get values from spectrum shield
  mapSpectrum();      // Color pixels according to spectrum values      
  delay(15);
 
  // Get current button state.
  bool newState = digitalRead(BUTTON_PIN);
 
  // Check if state changed from high to low (button press).
  if (newState == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      showType++;
      if (showType > 7)
        showType=1;
      startShow(showType);
    }
  }
// Set the last button state to the old state.
  oldState = newState;
}
 
void readSpectrum()
{
  // Band 0 = Lowest Frequencies.
  byte Band;
  for(Band=0;Band <7; Band++)
  {
    SpectrumLeft[Band] = analogRead(A0); //left
    SpectrumRight[Band] = analogRead(A1); //right
   
    digitalWrite(pinStrobe,HIGH);
    digitalWrite(pinStrobe,LOW);
    delayMicroseconds(50);
       }  
}
 
void mapSpectrum()    // map spectrum to pixel strips
{
  for(byte Band=0 ; Band <7 ; Band++)
  {    
    SpectrumLeft[Band] = map(SpectrumLeft[Band],100 , 950, 0, 19);
    SpectrumRight[Band] = map(SpectrumRight[Band], 100, 950, 0, 19);
  
  for(int Pixel = 0; Pixel < SpectrumLeft[Band]; Pixel++){
    Strip.setPixelColor(SpectrumGraphLeft[Band][Pixel], red[Pixel], green[Pixel], blue[Pixel]);
}
                for (byte Pixel = SpectrumLeft[Band] ; Pixel < 20 ; Pixel++)
                                {      // Turn the rest OFF!
                                               Strip.setPixelColor(SpectrumGraphLeft[Band][Pixel], OffColor);
                                }    // end for (Pixel
 
   for(int Pixel = 0; Pixel < SpectrumRight[Band]; Pixel++){
    Strip.setPixelColor(SpectrumGraphRight[Band][Pixel], red[Pixel],green[Pixel],blue[Pixel]);
}
                for (byte Pixel = SpectrumRight[Band] ; Pixel < 20 ; Pixel++)
                                {      // Turn the rest OFF!
                                               Strip.setPixelColor(SpectrumGraphRight[Band][Pixel], OffColor);
                                }    // end for (Pixel

  }    // end for (Band
  Strip.show();
}

[/color]

Edcastillo09:
I looked into the comma operator, but I'm not sure how I can use that to my benefit...

You can't. The comma operator is essentially worthless junk. Stop using it.