Audio To Multiple LED Strip Light Show System Advice Please!

Here’s the color layout.

63Hz-Blue

160Hz-Red

400Hz-Green

1k-Blue

2.5k-Green

6.25k-Red

I’ll look at the mapping function right now. However, why would the smoothing application slow it down for the 3 seconds? Could we impliment the same concept of mapping for overall light brightness? When it’s quiet music playing, the “maximum” value is 128, and after reaching a certain maximum volume, its at 255?..Before I get myself confused, because this is very similar to mapping by music loudness, but the point was to not subtract the noise directly. Do you have a simpler way of working with these ideas?

kdolf:
However, why would the smoothing application slow it down for the 3 seconds?

The smoothing algorithm is a running average of N samples, you set N. Imagine a quiet passage where the average is perhaps 50. Then the music becomes louder, say the sample jumps to 200. One sample of 200 averaged with a lot of 50's isn't going to raise that smoothed output much above 50. It'll take N/2 'loud' samples to move the smoothed output up to halfway between 'quiet' and 'loud'. So your light display will lag behind the music, how far depends on N and the sample rate. FWIW I believe the IC on the shield does some 'smoothing' already.

Ohhh okay, I see what you’re saying. So we won’t use it then! Is there anything else, I should know about the coding process? I still need to find a signle digital PWM code for one of the pins.

http://forum.arduino.cc/index.php/topic,19451.0.html

I’ve not looked at the library above but it seems worth a look and a try.

Hey, I’ve been looking around too. Can you look at this library, this looks really promising from the files I can open, but I can’t open the library itself entirely. https://learn.adafruit.com/fft-fun-with … s/software

If you look at that library, it’s for a Teensy 3.0, which is a much higher powered MCU than your basic Arduino. That code won’t run on an Uno. What would you use it for ?

the concepts in the arduino files

ignore my last post. This is the closest thing I’ve found to code and a visual of my project. http://russe11m.blogspot.com/2013/08/ar … oller.html

Mee_n_Mac, can you look at this code and see if anything looks odd?

#include <math.h>
#include <SoftPWM.h>

enum audio
{
	MONO,
	RIGHT,
	LEFT
};

// Constants
const boolean logMode = true;       	   	// enable or disable log mode display
const boolean debug = false;            	// enable or disable debug measurements and printouts
const int audio = MONO;						// audio mode
const int noise[] =
	{80, 80, 80, 80, 80, 80, 80};			// set this to magnitude of noise from shield
const float gain[] =
	{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};	// gain for each band
const unsigned long loop_delay = 1;      	// loop delay to slow down display update rate

// Pin assignments
const byte analogPinL = 0;              	// left channel analog data from shield
const byte analogPinR = 1;              	// right channel analog data from shield
const byte strobePin = 4;	      			// data strobe for shield
const byte resetPin = 5;	     		 	// reset strobe for shield
const byte ledPins[6] = {2,3,6,9,10,11};	// LEDs

int spectrumReadR;							// R magnitude from shield
int spectrumReadL;							// L magnitude from shield
int mag[7] = 
	{0.0,0.0,0.0,0.0,0.0,0.0,0.0};			// magnitudes of 7 freq band
int brightnessVal;							// 8 bit PWM value used to control brightness of LED


void setup() {
	// See http://arduino.cc/en/reference/serial for information about reading/writing through the serial port on the Arduino. Used for debugging purposes.
	Serial.begin(9600);

	// Initialize the pins
	pinMode(analogPinR, INPUT);
	pinMode(analogPinL, INPUT);
	pinMode(resetPin, OUTPUT);
	pinMode(strobePin, OUTPUT);
	for (int i = 0; i < 6; i++)
	{
		pinMode(ledPins[i], OUTPUT);
	}

	// Set the initial states
	digitalWrite(resetPin, LOW);
	digitalWrite(strobePin, LOW);
	for (int i = 0; i < 6; i++)
	{
		digitalWrite(ledPins[i], LOW);
	}

	// Initialize SoftPWM
	SoftPWMBegin();

	// Set analogPin's reference voltage (not sure if necessary)
	analogReference(DEFAULT);				// 5V

	// Initialize spectrum analyzer
	digitalWrite(resetPin,HIGH);
	delayMicroseconds(5);
	digitalWrite(strobePin,HIGH);
	delayMicroseconds(50);              	// strobe PW > 18 usec min
	digitalWrite(strobePin,LOW);
	delayMicroseconds(5);          	    	// reset PW > 100 nsec min
	digitalWrite(resetPin,LOW);
	delayMicroseconds(5);
	digitalWrite(strobePin,HIGH);
	delayMicroseconds(100);             	// reset to strobe falling > 72 usec min
}

void loop() {
	for(byte band = 1; band <= 7; band++){
		// Bring strobe low to switch shield output to next band
		digitalWrite(strobePin,LOW);
		delayMicroseconds(40);              // 36 usec min for output to settle

		// Data is now available on analog pins 0 and 1
		spectrumReadR = analogRead(analogPinR);
		spectrumReadL = analogRead(analogPinL);

		if(debug){
			Serial.print("Right chan reads ");
			Serial.print(spectrumReadR);
			Serial.print(" for band ");
			Serial.println(band);
			Serial.print("Left chan reads ");
			Serial.print(spectrumReadL);
			Serial.print(" for band ");
			Serial.println(band);
		}

		// Now set strobe back to high
		digitalWrite(strobePin, HIGH);

		// Combine L/R data as dictated by setting
		switch (audio) {
			case MONO:
				// this averages the L & R readings
				mag[band-1] = (spectrumReadL + spectrumReadR)/2;
				break;
			case RIGHT:
				// this sets the magnitude = R data
				mag[band-1] = spectrumReadR;
				break;
			case LEFT:
				// this sets the magnitude = L data
				mag[band-1] = spectrumReadL;
				break;
			default:
				// this sets the magnitude = L data
				mag[band-1] = spectrumReadL;
				break;
		}

		if(debug){
			Serial.print("Magnitude is ");
			Serial.println(mag[band-1]);
		}
		
		// logMode - determines whether the volume-to-brightness ratio follows a linear or logarithmic scale
		if(logMode){
			// Convert to 20log of input
			mag[band-1] = 20.0*log10(mag[band-1]);

			// Map range of [noise]-60 to brightness value of 0-255
			brightnessVal = map(mag[band-1], noise[band-1], 60, 0, 255);
		}
		else{
			// Map range of [noise]-1023 to brightness value of 0-255
			brightnessVal = map(mag[band-1], noise[band-1], 1023, 0, 255);
		}

		// Ensure brightnessVal is 8 bit value
		brightnessVal = constrain(brightnessVal,0,255);

		if(debug){
			Serial.print("Brightness value is ");
			Serial.print(brightnessVal);
			Serial.print(" for band ");
			Serial.println(band);
		}

		// Output PWM to LED
		if (band < 7)	// ignore 7th band
		{
			switch (ledPins[band-1]) {
				case 2:
				case 4:
				case 7:
				case 8:
				case 12:	// SoftPWM pins
					SoftPWMSet(ledPins[band-1],brightnessVal);
					break;

				case 3:
				case 5:
				case 6:
				case 9:
				case 10:
				case 11:	// Normal PWM pins
					analogWrite(ledPins[band-1],brightnessVal);
					break;

				default:	// Invalid pin
					if (debug)
					{
						Serial.print("Pin value ");
						Serial.print(ledPins[band-1]);
						Serial.println(" is invalid.");
					}
					break;
			}
		}
	}

	if(debug){
		Serial.println();
	}

	// loop_delay - adjust this variable so that the time it takes to execute this loop() code matches up with the delay of updating the LED brightness (done via trial and error)
	delay(loop_delay);
}

kdolf:
Mee_n_Mac, can you look at this code and see if anything looks odd?

Sure but it'll be a couple of days. I'm tied up ATM.

(Hint : never, never, never buy an Mini. Or an Audi. Or a VW.)

kdolf:
Mee_n_Mac, can you look at this code and see if anything looks odd?

I don't understand what your intent was here. Can you explain how the code is supposed to work ?
          if (band < 7)   // ignore 7th band
          {
             switch (ledPins[band-1]) {
                case 2:
                case 4:
                case 7:
                case 8:
                case 12:   // SoftPWM pins
                   SoftPWMSet(ledPins[band-1],brightnessVal);
                   break;

                case 3:
                case 5:
                case 6:
                case 9:
                case 10:
                case 11:   // Normal PWM pins
                   analogWrite(ledPins[band-1],brightnessVal);
                   break;

                default:   // Invalid pin
                   if (debug)
                   {
                      Serial.print("Pin value ");
                      Serial.print(ledPins[band-1]);
                      Serial.println(" is invalid.");
                   }
                   break;
             }
          }

Also if you’re never going to use log mode or stereo, you might as well simplify the code in those regards. Less code, simpler code is always better than complex code that isn’t used.

Hey Mee_n_Mac,

I’m the guy who wrote this code. Not familiar with Arduinos, but I am familiar with C++ and programming in general. Anyways, in response to your question, the purpose of this switch statement is so that the code automatically determines whether or not to use SoftPWM. It makes this determination under the assumption that pins 3,5,6,9,10,11 are PWM pins and therefore can output PWM pulses just by using analogWrite(). All the other available pins must use SoftPWMSet() in order to work. The pins in use are stored in the ‘ledPins’ array, so ‘ledPins[band-1]’ selects the pin value for the current band in question which is what the switch is based on.

Most of the code structure is designed for easy switching/playing around with while we’re in a preliminary state (e.g. with the switch you’re asking about, if you want to switch some of the led pins around on the board, all you have to do is change the pin values in the ledPins array and the code takes care of the rest), but since this is such a low level of programming (something I’m not used to), it might be causing more harm than help.

My good friend Tom is helping me with the coding aspect. He thought he responded already, but he can explain it better than me. Mee, I can give you debug info, but from the code your seeing something just isn’t clicking. I have simulated my system with 2 RGB LED pins, and with the code I’m getting continuous white light. No pulsation or different brightnesses. Why? If we were trying to get the top 40% of the magnitudes, wouldn’t logMode simulate that? Or the numbers are too similiar that that explains why it’s almost white light. Here’s some code from our last test and debug output.

And hey right now I feel ya on those issues. Your car issues, my ledstrip issues. It’s been over 16 days, they have be “rejected” from airport security twice. The company lost my tracking number, username and password, and no one will respond to my last ticket. Sounds like I got scammed off http://www.dx.com

#include <math.h>
#include <SoftPWM.h>

enum audio
{
	MONO,
	RIGHT,
	LEFT
};

// Constants
const boolean logMode = true;       	   	// enable or disable log mode display
const boolean debug = true;           	 	// enable or disable debug measurements and printouts
const int audio = MONO;						// audio mode
const int noise[] =
	{0, 0, 0, 0, 0, 0, 0};					// set this to magnitude of noise from shield
const unsigned long loop_delay = 200;      	// loop delay to slow down display update rate

// Pin assignments
const byte analogPinL = 0;              	// left channel analog data from shield
const byte analogPinR = 1;              	// right channel analog data from shield
const byte strobePin = 4;	      			// data strobe for shield
const byte resetPin = 5;	     		 	// reset strobe for shield
const byte ledPins[6] = {2,3,6,9,10,11};	// LEDs

int spectrumReadR;							// R magnitude from shield
int spectrumReadL;							// L magnitude from shield
int mag[] = 
	{0.0,0.0,0.0,0.0,0.0,0.0,0.0};			// magnitudes of 7 freq band
int logMag;									// magnitude for logMode
int logNoise[] =
	{0,0,0,0,0,0,0};						// noise values for logMode
int brightnessVal;							// 8 bit PWM value used to control brightness of LED


void setup() {
	// See http://arduino.cc/en/reference/serial for information about reading/writing through the serial port on the Arduino. Used for debugging purposes.
	Serial.begin(9600);

	// Initialize the pins
	pinMode(analogPinR, INPUT);
	pinMode(analogPinL, INPUT);
	pinMode(resetPin, OUTPUT);
	pinMode(strobePin, OUTPUT);
	for (int i = 0; i < 6; i++)
	{
		pinMode(ledPins[i], OUTPUT);
	}

	// Set the initial states
	digitalWrite(resetPin, LOW);
	digitalWrite(strobePin, LOW);
	for (int i = 0; i < 6; i++)
	{
		digitalWrite(ledPins[i], LOW);
	}

	// Initialize SoftPWM
	SoftPWMBegin();

	// Set analogPin's reference voltage (not sure if necessary)
	analogReference(DEFAULT);				// 5V

	// Calculate noise levels for log mode
	if (logMode)
	{
		for (int i = 0; i <= 6; ++i)
		{
			logNoise[i] = 20.0*log10(noise[i]);
		}
	}

	// Initialize spectrum analyzer
	digitalWrite(resetPin,HIGH);
	delayMicroseconds(5);
	digitalWrite(strobePin,HIGH);
	delayMicroseconds(50);              	// strobe PW > 18 usec min
	digitalWrite(strobePin,LOW);
	delayMicroseconds(5);          	    	// reset PW > 100 nsec min
	digitalWrite(resetPin,LOW);
	delayMicroseconds(5);
	digitalWrite(strobePin,HIGH);
	delayMicroseconds(100);             	// reset to strobe falling > 72 usec min
}

void loop() {
	for(byte band = 1; band <= 7; band++){
		// Bring strobe low to switch shield output to next band
		digitalWrite(strobePin,LOW);
		delayMicroseconds(40);              // 36 usec min for output to settle

		// Data is now available on analog pins 0 and 1
		spectrumReadR = analogRead(analogPinR);
		spectrumReadL = analogRead(analogPinL);

		if(debug){
			Serial.print("Right chan reads ");
			Serial.print(spectrumReadR);
			Serial.print(" for band ");
			Serial.println(band);
			Serial.print("Left chan reads ");
			Serial.print(spectrumReadL);
			Serial.print(" for band ");
			Serial.println(band);
		}

		// Now set strobe back to high
		digitalWrite(strobePin, HIGH);

		// Combine L/R data as dictated by setting
		switch (audio) {
			case MONO:
				// this averages the L & R readings
				mag[band-1] = (spectrumReadL + spectrumReadR)/2;
				break;
			case RIGHT:
				// this sets the magnitude = R data
				mag[band-1] = spectrumReadR;
				break;
			case LEFT:
				// this sets the magnitude = L data
				mag[band-1] = spectrumReadL;
				break;
			default:
				// this sets the magnitude = L data
				mag[band-1] = spectrumReadL;
				break;
		}

		if(debug){
			Serial.print("Magnitude is ");
			Serial.println(mag[band-1]);
		}
		
		// logMode - determines whether the volume-to-brightness ratio follows a linear or logarithmic scale
		if(logMode){
			// Convert to 20log of input
			logMag = 20.0*log10(mag[band-1]);

			if(debug){
				Serial.print("Using log mode. New magnitude is ");
				Serial.print(logMag);
				Serial.print(" with noise value of ");
				Serial.println(logNoise[band-1]);
			}

			// Map range of [noise]-60 to brightness value of 0-255
			brightnessVal = map(logMag, logNoise[band-1], 60, 0, 255);
		}
		else{
			// Map range of [noise]-1023 to brightness value of 0-255
			brightnessVal = map(mag[band-1], noise[band-1], 1023, 0, 255);
		}

		// Ensure brightnessVal is 8 bit value
		brightnessVal = constrain(brightnessVal,0,255);

		if(debug){
			Serial.print("Brightness value is ");
			Serial.print(brightnessVal);
			Serial.print(" for band ");
			Serial.println(band);
		}

		SoftPWMSet(ledPins[band-1], brightnessVal);

		// Output PWM to LED
		// if (band < 7)	// ignore 7th band
		// {
		// 	switch (ledPins[band-1]) {
		// 		case 2:
		// 		case 4:
		// 		case 7:
		// 		case 8:
		// 		case 12:	// SoftPWM pins
		// 			SoftPWMSet(ledPins[band-1],brightnessVal);
		// 			break;

		// 		case 3:
		// 		case 5:
		// 		case 6:
		// 		case 9:
		// 		case 10:
		// 		case 11:	// Normal PWM pins
		// 			analogWrite(ledPins[band-1],brightnessVal);
		// 			break;

		// 		default:	// Invalid pin
		// 			if (debug)
		// 			{
		// 				Serial.print("Pin value ");
		// 				Serial.print(ledPins[band-1]);
		// 				Serial.println(" is invalid.");
		// 			}
		// 			break;
		// 	}
		// }
	}

	if(debug){
		Serial.println();
	}

	// loop_delay - adjust this variable so that the time it takes to execute this loop() code matches up with the delay of updating the LED brightness (done via trial and error)
	delay(loop_delay);
}

tjs352:
Hey Mee_n_Mac,

I’m the guy who wrote this code. Not familiar with Arduinos, but I am familiar with C++ and programming in general. Anyways, in response to your question, the purpose of this switch statement is so that the code automatically determines whether or not to use SoftPWM. It makes this determination under the assumption that pins 3,5,6,9,10,11 are PWM pins and therefore can output PWM pulses just by using analogWrite(). All the other available pins must use SoftPWMSet() in order to work.

OK I see, it just isn't complete yet according to the OP's mapping of frequency bands to colors and strips. Makes sense now.

63Hz-Blue

160Hz-Red

400Hz-Green

1k-Blue

2.5k-Green

6.25k-Red

kdolf:
I can give you debug info, but from the code your seeing something just isn’t clicking. I have simulated my system with 2 RGB LED pins, and with the code I’m getting continuous white light. No pulsation or different brightnesses. Why? If we were trying to get the top 40% of the magnitudes, wouldn’t logMode simulate that? Or the numbers are too similiar that that explains why it’s almost white light. Here’s some code from our last test and debug output.

Log mode will tend to collapse a large range of magnitudes from the shield into a smaller range of brightness values and that's what I'm seeing in your test data. Try using linear mode for now. I'm not sure log mode was ever used and thus fully debugged (for it's usability in real life). As far as getting white light, that's a consequence of driving the R, G and B LEDs at the same PWM value. A low duty cycle (= low PWM value) will be a dim white light, a high DC (PWM > 230) is a bright white light.

Wouldn’t it depend on the output of each pin for the led? Equal brightnesses of each color is what creates white light, how does it depend on duty cycles? Like you said the duty cycle would only effect the overall brightness but not the color of light.

kdolf:
Wouldn’t it depend on the output of each pin for the led? Equal brightnesses of each color is what creates white light, how does it depend on duty cycles? Like you said the duty cycle would only effect the overall brightness but not the color of light.

If I understood your post above, you have a pair of RGB LEDs, each LED driven from a single pin ... R, G and B all from the same pin. I also notice that all the magnitudes are roughly the same across all the bands. If you have a tone generator or some other sound source, try using those just to see the results (literally).

Sorry, it’s still the same set up as always. We have 2 pairs of RGB strips, each pair is driven by 3 pins. A red, green, and blue wire/pin. Totaling to 6 from the Leds

kdolf:
Sorry, it’s still the same set up as always. We have 2 pairs of RGB strips, each pair is driven by 3 pins. A red, green, and blue wire/pin. Totaling to 6 from the Leds

I misunderstood the post above then. Still the magnitudes you're getting for all the frequency bands are about the same, close enough to make the output look white. I don't know what you're using for source (music) material or what control (bass, treble, etc) you have over it. Perhaps try using some online test tones.

http://www.audiocheck.net/soundtestsaud … _index.php

Hey Mee,

we are working on the code and it’s coming along however; this is our latest issue. We now have a system and code that has the lights changing. The brightness is good, it’s fading…bluh bluh everything the code is telling it to do. But, it takes about 800 ms for each loop cycle. Each band being read is taking about 120ms. Why is it so slow and what can we do to fix it? Here’s some serial print. The code is below as well, some but not many changes from the one listed above.

Right chan reads 58 for band 1
Left chan reads 258 for band 1
Magnitude is 158
Brightness value is 215 for band 1
Band #0 elapsed time: 122 ms
Right chan reads 58 for band 2
Left chan reads 243 for band 2
Magnitude is 150
Brightness value is 255 for band 2
Band #1 elapsed time: 123 ms
Right chan reads 71 for band 3
Left chan reads 395 for band 3
Magnitude is 233
Brightness value is 0 for band 3
Band #2 elapsed time: 121 ms
Right chan reads 57 for band 4
Left chan reads 312 for band 4
Magnitude is 184
Brightness value is 82 for band 4
Band #3 elapsed time: 122 ms
Right chan reads 70 for band 5
Left chan reads 436 for band 5
Magnitude is 253
Brightness value is 0 for band 5
Band #4 elapsed time: 120 ms
Right chan reads 38 for band 6
Left chan reads 151 for band 6
Magnitude is 94
Brightness value is 255 for band 6
Band #5 elapsed time: 122 ms
Right chan reads 63 for band 7
Left chan reads 263 for band 7
Magnitude is 163
Brightness value is 189 for band 7
Band #6 elapsed time: 123 ms
Loop elapsed time: 1071 ms
#include <math.h>
#include <SoftPWM.h>

enum audio
{
	MONO,
	RIGHT,
	LEFT
};

// Constants
const boolean logMode = false;       	   	// enable or disable log mode display
const boolean debug = true;           	 	// enable or disable debug measurements and printouts
const int audio = MONO;						// audio mode
const int noise[] =
	{80, 80, 80, 80, 80, 80, 80};					// set this to magnitude of noise from shield
const unsigned long loop_delay = 0;    	// loop delay to slow down display update rate

// Pin assignments
const byte analogPinL = 0;              	// left channel analog data from shield
const byte analogPinR = 1;              	// right channel analog data from shield
const byte strobePin = 4;	      			// data strobe for shield
const byte resetPin = 5;	     		 	// reset strobe for shield
const byte ledPins[6] = {2,3,6,9,10,11};	// LEDs

int spectrumReadR;							// R magnitude from shield
int spectrumReadL;							// L magnitude from shield
int mag[] = 
	{0,0,0,0,0,0,0};			// magnitudes of 7 freq band
int logMag;									// magnitude for logMode
int logNoise[] =
	{0,0,0,0,0,0,0};						// noise values for logMode
int brightnessVal;							// 8 bit PWM value used to control brightness of LED
unsigned long startTime, endTime, startLEDTime, endLEDTime;                           // time in milliseconds


void setup() {
	// See http://arduino.cc/en/reference/serial for information about reading/writing through the serial port on the Arduino. Used for debugging purposes.
	Serial.begin(9600);

	// Initialize the pins
	pinMode(analogPinR, INPUT);
	pinMode(analogPinL, INPUT);
	pinMode(resetPin, OUTPUT);
	pinMode(strobePin, OUTPUT);
	for (int i = 0; i < 6; i++)
	{
		pinMode(ledPins[i], OUTPUT);
	}

	// Set the initial states
	digitalWrite(resetPin, LOW);
	digitalWrite(strobePin, LOW);
	for (int i = 0; i < 6; i++)
	{
		digitalWrite(ledPins[i], HIGH);
	}

	// Initialize SoftPWM
	SoftPWMBegin();

	// Set analogPin's reference voltage (not sure if necessary)
	analogReference(DEFAULT);	// 5V

	// Calculate noise levels for log mode
	if (logMode)
	{
		for (int i = 0; i <= 6; ++i)
		{
			logNoise[i] = 20.0*log10(noise[i]);
		}
	}

	// Initialize spectrum analyzer
	digitalWrite(resetPin,HIGH);
	delayMicroseconds(5);
	digitalWrite(strobePin,HIGH);
	delayMicroseconds(50);              	// strobe PW > 18 usec min
	digitalWrite(strobePin,LOW);
	delayMicroseconds(5);          	    	// reset PW > 100 nsec min
	digitalWrite(resetPin,LOW);
	delayMicroseconds(5);
	digitalWrite(strobePin,HIGH);
	delayMicroseconds(100);             	// reset to strobe falling > 72 usec min
}

void loop() {
        startTime = millis();
	for(byte band = 1; band <= 7; band++){
                startLEDTime = millis();
		// Bring strobe low to switch shield output to next band
		digitalWrite(strobePin,LOW);
		//delayMicroseconds(40);              // 36 usec min for output to settle

		// Data is now available on analog pins 0 and 1
		spectrumReadR = analogRead(analogPinR);
		spectrumReadL = analogRead(analogPinL);

		if(debug){
			Serial.print("Right chan reads ");
			Serial.print(spectrumReadR);
			Serial.print(" for band ");
			Serial.println(band);
			Serial.print("Left chan reads ");
			Serial.print(spectrumReadL);
			Serial.print(" for band ");
			Serial.println(band);
		}

		// Now set strobe back to high
		digitalWrite(strobePin, HIGH);

		// Combine L/R data as dictated by setting
		switch (audio) {
			case MONO:
				// this averages the L & R readings
				mag[band-1] = (spectrumReadL + spectrumReadR)/2;
				break;
			case RIGHT:
				// this sets the magnitude = R data
				mag[band-1] = spectrumReadR;
				break;
			case LEFT:
				// this sets the magnitude = L data
				mag[band-1] = spectrumReadL;
				break;
			default:
				// this sets the magnitude = L data
				mag[band-1] = spectrumReadL;
				break;
		}

		if(debug){
			Serial.print("Magnitude is ");
			Serial.println(mag[band-1]);
		}
		
		// logMode - determines whether the volume-to-brightness ratio follows a linear or logarithmic scale
		if(logMode){
			// Convert to 20log of input
			logMag = 20.0*log10(mag[band-1]);

			if(debug){
				Serial.print("Using log mode. New magnitude is ");
				Serial.print(logMag);
				Serial.print(" with noise value of ");
				Serial.println(logNoise[band-1]);
			}

			// Map range of [noise]-60 to brightness value of 0-255
			brightnessVal = map(logMag, logNoise[band-1], 60, 255, 0);
		}
		else{
			// Map range of [noise]-1023 to brightness value of 0-255
			brightnessVal = map(mag[band-1], 150, 200, 255, 0);
		}

		// Ensure brightnessVal is 8 bit value
		brightnessVal = constrain(brightnessVal,0,255);

		if(debug){
			Serial.print("Brightness value is ");
			Serial.print(brightnessVal);
			Serial.print(" for band ");
			Serial.println(band);
		}
                
                if (band < 7) {
		  SoftPWMSet(ledPins[band-1], brightnessVal);
                }

		// Output PWM to LED
		// if (band < 7)	// ignore 7th band
		// {
		// 	switch (ledPins[band-1]) {
		// 		case 2:
		// 		case 4:
		// 		case 7:
		// 		case 8:
		// 		case 12:	// SoftPWM pins
		// 			SoftPWMSet(ledPins[band-1],brightnessVal);
		// 			break;

		// 		case 3:
		// 		case 5:
		// 		case 6:
		// 		case 9:
		// 		case 10:
		// 		case 11:	// Normal PWM pins
		// 			analogWrite(ledPins[band-1],brightnessVal);
		// 			break;

		// 		default:	// Invalid pin
		// 			if (debug)
		// 			{
		// 				Serial.print("Pin value ");
		// 				Serial.print(ledPins[band-1]);
		// 				Serial.println(" is invalid.");
		// 			}
		// 			break;
		// 	}
		// }
                endLEDTime = millis();
                if(debug) {
                  Serial.print("Band #");
                  Serial.print(band-1);
                  Serial.print(" elapsed time: ");
                  Serial.print(endLEDTime-startLEDTime);
                  Serial.println(" ms");
                }
	}

	// loop_delay - adjust this variable so that the time it takes to execute this loop() code matches up with the delay of updating the LED brightness (done via trial and error)
	delay(loop_delay);
        
        endTime = millis();
        if(debug) {
          Serial.print("Loop elapsed time: ");
          Serial.print(endTime-startTime);
          Serial.println(" ms");
        }
        
	if(debug){
		Serial.println();
	}
}