# Connect intensity microphone to glow-size in LED Matrix?

I searched the old/new forum for answers, but hopefully you guys can help me with this seemingly question :.

I have a LED matrix (12x12) using Bliptronics’ LEDPixels using a clock and dataline. I defined rows and columns, so I can turn on specific pixels in the grid. What I want to achieve in the end is quite complex I guess, so for this question I’ll break it down to solve one problem at a time.

I connected a microphone to my Arduino, and what I want to do is simply connect the intensity of the sound, to the size of the ‘glow’ to appear on the matrix. So let’s say there is no sound (EG: value 0), only the centre LED is on. When I start talking (EG: values 100-300), the surrounding LED’s will light up as well. When I start talking louder and louder (EG: values 300-500) another ring of LED’s lights up, etc. etc. So that the louder the sounds, the bigger this glow on my grid gets. I want this glow to be able to appear anywhere on the grid, so not being pinned down to specific coordinates.

I know I can workaround it by creating dozens of ‘if statements’, but that’s not a solid solution. I guess I need a way so that the program can determine which are the surrounding LEDs of the ‘core’ of the glow, and based upon that can light up new rings of LED’s. Can you guys help me giving keywords or examples codes to look at?

three steps

1. learn how to deal with the microphone, you probably need some amp, there are multiple projects discussed on the forum, just search

2. The volume is what is read by the analogRead() => more fun - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1286718155

3. different strategies for the leds are possible

• (simple version) just choose N random leds

• create an array of arrays: this hold the r,c positions of the leds to switch on @ certain volume level.

• choose a midpoint (x,y)

• add this midpoint to every LEDposition (modulo 12) to find the positions to switch on

So no if’s needed, just a big datastructure. As the r,c coordinates are all 0-11, two of them fit into a byte, because a full the matrix would be realy big I propose to make 6 separate array’s. As the coordinates are all 0…11 both fit into one byte with the following math

byte = row * 16 + column;
row = byte / 16;
column = byte & 0x0F;

The arrays are filled hexadecimal as this makes it easy to see the coordinates!
uint8_t level1 [1] = {0x33};
uint8_t level2 [8] = {0x22, 0x23, 0x24, 0x32, 0x34, 0x42, 0x43, 0x44 };
uint8_t level3 [16] = {0x11, 0x12, 0x13, 0x14, 0x15, etc
uint8_t level4 [24] =
uint8_t level5 [32] =
uint8_t level6 [40]

In the main loop there will be one switch

switch(volumeLevel)
{
case 6: switchOn(level6, 40);
case 5: switchOn(level5, 32);
case 4: switchOn(level4, 24);
case 3: switchOn(level3, 16);
case 2: switchOn(level2, 8);
case 1: switchOn(level1, 1);
default:
}
due to the fall through in the switch statement the right leds will put on

switchOn(byte* ar, int size)
{
for (i=0; i< size; i++) switchOnLED(ar_/16, ar & 0x0F);_
}
sofar my 2 cents

Thanks Rob! I already created several microphones, amplification PCB's and code that averages out the incoming signal, so that's set. The code you put there looks interesting, I'll have a look how that works with the library I use for controlling the LED's through PWM. It should work I guess?