 
 // Set color based on frequency and brightness
 void setColor(int peak_index, int brightness) {
-    struct Color {
-        int red;
-        int green;
-        int blue;
-    };
-    
-    struct Color full_spectrum[24] = {
-        {  25,   0, 100 },  // indigo
-        {   0,   0, 100 },  // blue
-        {   0,  25, 100 },  // med. blue
-        {   0,  50, 100 },  // sky blue
-        {   0,  75, 100 },  // pale blue
-        {   0, 100, 100 },  // cyan
-        {   0, 100,  75 },  // pale green
-        {   0, 100,  50 },  // grass green
-        {   0, 100,  25 },  // bright green
-        {   0, 100,   0 },  // green
-        {  25, 100,   0 },  // lime
-        {  50, 100,   0 },  // bright lime
-        {  75, 100,   0 },  // neon lime
-        { 100, 100,   0 },  // yellow
-        { 100,  75,   0 },  // orange
-        { 100,  50,   0 },  // med. orange
-        { 100,  25,   0 },  // dark orange
-        { 100,   0,   0 },  // red
-        { 100,   0,  25 },  // pink
-        { 100,   0,  50 },  // bright pink
-        { 100,   0,  75 },  // hot pink
-        { 100,   0, 100 },  // purple
-        { 100,  50, 100 },  // hot purple
-        { 100, 100, 100 }   // white hot
-    };
-    
-    Color color_palette[24];
-    uint32_t strip_color = strip.Color(0, 0, 0);
-    
-    for (int i = 0; i < 24; i++) {
-        color_palette[i] = full_spectrum[i];
-    }
-
     if (peak_index == 0) {
         // signal was weak, turn lights off
-        strip_color = strip.Color(0, 0, 0);
-    } else if (peak_index == -1) {
-        // do nothing, use last color
+        red = 0;
+        green = 0;
+        blue = 0;
     } else if (peak_index > 24) {
-        strip_color = strip.Color(
-            round(color_palette[23].red   * brightness / 127),
-            round(color_palette[23].green * brightness / 127),
-            round(color_palette[23].blue  * brightness / 127)
-        );
+        red = color_palette[23].red;
+        green = color_palette[23].green;
+        blue = color_palette[23].blue;  
     } else {
-        strip_color = strip.Color(
-            round(color_palette[peak_index - 1].red   * brightness / 127),
-            round(color_palette[peak_index - 1].green * brightness / 127),
-            round(color_palette[peak_index - 1].blue  * brightness / 127)
-        );
+        red = color_palette[peak_index - 1].red;
+        green = color_palette[peak_index - 1].green;
+        blue = color_palette[peak_index - 1].blue;        
+    }
+    
+    strip_color = strip.Color(
+        round(red   * brightness / 127),
+        round(green * brightness / 127),
+        round(blue  * brightness / 127)
+    );
+    
+    if (DEBUG) {
+        Serial.print(color_palette[peak_index - 1].red);
+        Serial.print("\t");
+        Serial.print(color_palette[peak_index - 1].green);
+        Serial.print("\t");
+        Serial.println(color_palette[peak_index - 1].blue);
     }
     
     for (int i=0; i < strip.numPixels(); i++) {

#define LIN_OUT 1 // use the linear output function
#define FFT_N 128 // set number of FFT points
#define DEBUG 1   // set to 1 to turn on Serial printing

#include <math.h>
#include <FFT.h>
#include "LPD8806.h"
#include "SPI.h"

int peak_index;
int max_value;
int sum_fft;
float frequency;
float SAMPLE_RATE = 9600.0;
int SKIP_MULT = 8;
int MAX_FFT_BIN = 16383;

/*
 * used to cut the lights, 
 * some sources (iPhone) have amps that create a bit of noise that 
 * remains on for a few seconds even after music is stopped or paused.
 * Perhaps this doesn't occur on mixers, and it may be possible to
 * eliminate with an OpAmp and/or low pass filter circuit
 */
int MIN_FFT_SUM = 100;

// LEDeez
int brightness;  // controls the LED brightness based on dB level
// LEDs can be set up to 127, but it seems too bright so we tone it down a bit
int MAX_BRIGHTNESS = 127;

float base_freak = SAMPLE_RATE / FFT_N / 2;

// Number of RGB LEDs in strand:
int nLEDs = 160;

// Chose 2 pins for output; can be any valid output pins:
int dataPin  = 2;
int clockPin = 3;

// First parameter is the number of LEDs in the strand.  The LED strips
// are 32 LEDs per meter but you can extend or cut the strip.  Next two
// parameters are SPI data and clock pins:
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);

void setup() {
    if (DEBUG) {

        if (max_value < fft_lin_out[i]) {
            // peak index determines frequency
            peak_index = i;
            // max value used as an additional check to turn the lights off
            max_value = fft_lin_out[i];
        }
        if (i > 0) {
            // control brightness by summing all bins except the first bin, 
            // i.e. the total power in the sample
            sum_fft += fft_lin_out[i];
        }
    }

    // Use sum_fft to determine brightness
    brightness = round(1.0 * max_brightness * sum_fft / MAX_FFT_BIN);
    
    // safety net in case our calculated brightness was out of range
    if (brightness > 127) {  // too much
        brightness = 127;
    } else if (brightness < 0) {  // too little
        brightness = 0;
    }
    
    // Reset peak_index to zero if signal is weak
    if (max_value < MIN_PEAK_VALUE || sum_fft < MIN_FFT_SUM) {
        peak_index = 0;        
    }
    
    setColor(peak_index, brightness);
            
    if (DEBUG) {
        frequency = peak_index * ((1.0 * SAMPLE_RATE / (SKIP_MULT / 2)) / (FFT_N / 2));
        
        Serial.print("FFT sum: ");
        Serial.print(sum_fft);
