Hi,
As part of my masters I am trying to create a prototype of a led matrix that responds to sounds that are picked up by a microphone. I have only been introduced to an arduino less then a month ago so bear with my lack of knowledge.
So far I have managed to build a working 5x5 led matrix, which works with other codes that do not rely on a mic input. However once I try to control it with sound I cant seem to get the code to work.
I have adapted a code supplied by gallactronics for a 8x8 matrix as follows:
const int rownum[5] = {
12,11,10,9,8};
// here you are naming the rows const
int colnum[5] = {
7,6,5,4,3};
//here you are naming the columns
int audioIn = A0;
int Vin = 0;
float audioVin = 0;
//now you are saying which LEDs to light at what amplitude
int blank[5][5] = {
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0}};
int minimum[5][5] = {
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}};
int drum[5][5] = {
{0,0,0,0,0},
{0,1,1,1,0},
{0,1,0,1,0},
{0,1,1,1,0},
{0,0,0,0,0}};
int mediocre[5][5] = {
{1,1,1,1,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,1,1,1,1}};
void setup() {
analogReference(EXTERNAL);
Serial.begin(19200);
// initialize the I/O pins as outputs:
// iterate over the pins:
for (int thisPin = 0; thisPin < 5; thisPin++) {
// initialize the output pins:
pinMode(colnum[thisPin], OUTPUT);
pinMode(rownum[thisPin], OUTPUT);
// take the col pins (i.e. the cathodes) high to ensure that
// the LEDS are off:
digitalWrite(colnum[thisPin], HIGH);
digitalWrite(rownum[thisPin], LOW); } }
void loop() {
// This could be rewritten to not use a delay, which would make it appear brighter
int audioVin = analogRead(A0);
Serial.println(audioVin, DEC);
//now you are specifying the ranges for the mp3 jack audio input voltage (audioVin)
if (audioVin < 6) { drawScreen(blank);
} else if(audioVin < 14) { drawScreen(minimum);
} else if (audioVin < 35) { drawScreen(drum);
} else if (audioVin < 45) { drawScreen(mediocre);
}
}
int row(int i) {
if(i == 1)
{ return A5;
} else if (i == 2)
{ return A4;
} else if (i == 3)
{ return A3;
} else if (i == 4)
{ return A2;
} else if (i == 5)
{ return 3;
}
}
int col(int i) {
if(i == 1)
{ return 7;
} else if (i == 2)
{ return 8;
} else if (i == 3)
{ return 9;
} else if (i == 4)
{ return 10;
} else if (i == 5)
{return 11;
}
}
void drawScreen(int character[5][5]) {
for(int j = 0; j < 5; j++) {
// Turn the row on
int rowNumber = j + 1;
digitalWrite(row(rowNumber), LOW);
for (int k = 0; k < 5; k++) {
// draw some letter bits
int columnNumber = k + 1;
if(character[j][k] == 1) {
digitalWrite(col(columnNumber), HIGH);
}
digitalWrite(col(columnNumber), LOW);
}
digitalWrite(row(rowNumber), HIGH);
}
}
When uploaded the LED Matrix does not respond at all! Using adafruits Electrect mic as shown here:
any clue where I am going wrong?
Thanks!






