One of my employees wrote this code although it does not seem to work on any pin past analog 3. It should be wired so that the electret microphone breakout board is wired to 3.3V to VCC, GND to GND, and the AUD to A1 and D2. Then for additional mics, AUD would go to A2 and D3 so on and so forth.
Code:
long count0,count1,count2,count3,count4;
long last;
double v0,v1,v2,v3,v4,voltage;
void bump0() {
count0++;
}
void bump1() {
count1++;
}
void bump2() {
count2++;
}
void bump3() {
count3++;
}
void bump4() {
count4++;
}
void setup() {
count0=0;
count1=0;
count2=0;
count3=0;
count4=0;
v0=0.0;
v1=0.0;
v2=0.0;
v3=0.0;
v4=0.0;
attachInterrupt(0,bump0,RISING);
attachInterrupt(1,bump1,RISING);
attachInterrupt(2,bump2,RISING);
attachInterrupt(3,bump3,RISING);
attachInterrupt(4,bump4,RISING);
last=millis();
Serial.begin(9600);
Serial.println("millis,f0(Hz),v0(v),f1(Hz),v1(v),f2(Hz),v2(v),f3(Hz),v3(v),f4(Hz),v4(v)");
}
void loop() {
long next=millis();
if (next-last>100) {
long c0,c1,c2,c3,c4;
c0=count0;
count0-=c0;
c1=count1;
count1-=c1;
c2=count2;
count2-=c2;
c3=count3;
count3-=c3;
c4=count4;
count4-=c4;
double dt=(next-last)/1000.0;
Serial.print(next-last);
Serial.print(',');
Serial.print(double(c0)/dt);
Serial.print(',');
Serial.print(v0);
Serial.print(',');
Serial.print(double(c1)/dt);
Serial.print(',');
Serial.print(v1);
Serial.print(',');
Serial.print(double(c2)/dt);
Serial.print(',');
Serial.print(v2);
Serial.print(',');
Serial.print(double(c3)/dt);
Serial.print(',');
Serial.print(v3);
Serial.print(',');
Serial.print(double(c4)/dt);
Serial.print(',');
Serial.println(v4);
v0=0.0;
v1=0.0;
v2=0.0;
v3=0.0;
v4=0.0;
last=next;
} else {
voltage=5.0*(double)abs(analogRead(0)-512)/1024.0;
if (voltage>v0) v0=voltage;
voltage=5.0*(double)abs(analogRead(1)-512)/1024.0;
if (voltage>v1) v1=voltage;
voltage=5.0*(double)abs(analogRead(2)-512)/1024.0;
if (voltage>v2) v2=voltage;
voltage=5.0*(double)abs(analogRead(3)-512)/1024.0;
if (voltage>v3) v3=voltage;
voltage=5.0*(double)abs(analogRead(4)-512)/1024.0;
if (voltage>v4) v4=voltage;
}
}
What seems to be wrong with it?