NeoPixel strip with Spectrum shield

Hi all,

I’m on with creating a simple project using a 1m strip of neopixels and a spectrum shield from sparkfun. At the moment i have the neopixel strip connected to the arduino and i have uploaded the Cylon Eye v1.10 script created by EternalCore to the board so that a single led chases back and forth.

I’ve also connected the spectrum shield to the arduino and played around with some example code to see it in action.

What I’d’ like my set-up to do is when the single led chases back and forth, it also changes colour to the music.

how would i go about making this happen. Ive included to two scripts that I’ve been playing with. is there any way i could combine the two together to get what i need.

or is there another way i could approach this task.

any help would be really grateful.

Chaser Code

#include <Adafruit_NeoPixel.h>


#define PIN 6
#define TPIXEL 144

int wait_T=40;
int refresh=1330;
int PixelCount=144; 
int Pixel_Start_End=0;
boolean UsingBar = false;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(TPIXEL, PIN, NEO_GRB + NEO_KHZ800); 


void setup() {
  strip.begin();
  strip.show(); 
}

void loop() {
      
  CylonEyeUp(strip.Color(255,255,255), strip.Color(0,0,0), strip.Color(0,0,0), wait_T, PixelCount, Pixel_Start_End);
  CylonEyeClear(wait_T, PixelCount, Pixel_Start_End);
  
}

void CylonEyeClear(uint8_t Delay, int TotalPixels, int pStart) {
  for(int i=pStart; i<TotalPixels+2; i++) {
    strip.setPixelColor(i, strip.Color(0,0,0)); 
     strip.show();
  }
}
void CylonEyeUp(uint32_t Co, uint32_t Ct, uint32_t Ctt, uint8_t Delay, int TotalPixels, int pStart) {
  for(int i=pStart; i<TotalPixels; i++) {
   if(!UsingBar) { strip.setPixelColor(i+2, Ctt); } 
    strip.setPixelColor(i+1, Ct);  
    strip.setPixelColor(i, Co);    
    strip.setPixelColor(i-1, Ct);  
    if(!UsingBar) { strip.setPixelColor(i-2, Ctt); } 

    if(!UsingBar) {
      strip.setPixelColor(i-3, strip.Color(0,0,0)); 
    } else {
      strip.setPixelColor(i-2, strip.Color(0,0,0)); 
    }
    strip.show();
    delay(Delay);

  }
}

Spectrum Code

#include <Adafruit_NeoPixel.h>

#define PIN_NEOPIXELS 6
#define PIN_STROBE 4
#define PIN_RESET 5
#define PIN_LEFT 0 //analog
#define PIN_RIGHT 1 //analog
 
#define NUMLEDSPERSEGMENT 144
#define NUMLEDS NUMLEDSPERSEGMENT * 1

#define MINPOWER 128
#define MAXPOWER 1023

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLEDS, PIN_NEOPIXELS, NEO_GRB + NEO_KHZ800);

//band arrays
int left[7]; 
int right[7];

void setup() {
   //initialize neopixels
   strip.begin();
   strip.setBrightness(32); //otherwise I'll become blind during testing ... ;)
   strip.show();

   //initialize eq
   pinMode(PIN_RESET, OUTPUT); // reset
   pinMode(PIN_STROBE, OUTPUT); // strobe
   digitalWrite(PIN_RESET,LOW); // reset low
   digitalWrite(PIN_STROBE,HIGH); //pin 5 is RESET on the shield
}

void loop() {
   readMSGEQ7();

   int rLeft = colorValue((left[0]+left[1])/2);
   int gLeft = colorValue((left[2]/2+left[3]+left[4]/2)/2);
   int bLeft = colorValue((left[5]+left[6])/2);

   int rRight = colorValue((right[0]+right[1])/2);
   int gRight = colorValue((right[2]/2+right[3]+right[4]/2)/2);
   int bRight = colorValue((right[5]+right[6])/2);

   for (int i = 0; i < NUMLEDSPERSEGMENT; i++) {
      strip.setPixelColor(i, (i<=rLeft) ? 255 : 0,(i<=gLeft) ? 255 : 0,(i<=bLeft) ? 255 : 0);   
      strip.setPixelColor(i + NUMLEDSPERSEGMENT, (i<=rRight) ? 255 : 0,(i<=gRight) ? 255 : 0,(i<=bRight) ? 255 : 0);   
   }

   strip.show();

   delay(40);
}

int colorValue(int powerValue) 
{
   return map(powerValue, MINPOWER, MAXPOWER, 0, NUMLEDSPERSEGMENT);
}

void readMSGEQ7()
{
   //reset the data
   digitalWrite(PIN_RESET, HIGH);
   digitalWrite(PIN_RESET, LOW);
   
   //loop thru all 7 bands
   for(int band=0; band < 7; band++) {
      digitalWrite(PIN_STROBE,LOW); // go to the next band 
      delayMicroseconds(50); //gather some data
      left[band] = analogRead(PIN_LEFT); // store left band reading
      right[band] = analogRead(PIN_RIGHT); // store right band reading
      digitalWrite(PIN_STROBE,HIGH); // reset the strobe pin
   }
}
is there any way i could combine the two together to get what i need.

Yes.

What, more specifically, do you need ? Is the color to change as a function of the volume of the music ? Is the color to change as a function of the frequency content ? Some details, in words, would go a long way to coming up with the code needed to bridge the 2 functions you’ve posted. Just as an example I might point out that you have 1 strip and (perhaps) 2 channels of input (left, right). For each channel you then get 7 frequency bands which will give you a “volume” of each channel ranging (ideally) from 0 to perhaps 1024. The output for the central pixel in the Cylon eye is some combination of R, G and B values ranging from 0 - 255. The other pixels RGB values would be some function of the central pixel’s.

So you might combine the left and right channels to get an average for each of the 7 bands. Then you might have the lower 2 bands averaged and set the R value. The middle 3 bands might set the G value, leaving the upper 2 bands to set the B value. You might use the map() function to go from the 0-1024 range to the 0-255 range for each of these. Perhaps you might subtract an offset first or employ a gain term. I don’t know. The “side” pixels might then be the same color but a fraction of the intensity of the center pixel.

There are many ways to set the color and intensity of a pixel from the music. The above is just one … and perhaps not even a good one (I have no idea of what it’ll look like).

Another detail would be the timing of the Eye as is goes left - right - left, and how/if to synchronize the sampling of the music to the eye movement timing.