never mind
unsigned long count = 0
unsigned long sum = 0
unsigned long starttime = millis();
while (millis() - starttime < 10)
{
sum+= analogRead();
count++
}
unsigned long avg = sum/count;
eds_law_:
Hi,I have a project consisting of an electret mic and an LCD and long story short the LCD displays volume data on the LCD in real time in decibels, and I have placed a 200ms loop delay to make the results readable.
However I would like to go on step further and I am aiming to average the results over a period of 8-10ms or something along those lines to the point where the code will average out the input voltage and display this on the LCD.
Can anybody help point me in the right direction how to do this??
Any help would be appreciated.Thanks
See if I am understanding what you are doing right now. Every 200 ms, you grab the volume in DB and display it.
What you are wanting to do is grab some number of DB values for 8-10 ms and display the average. Then repeat again after 200ms.
How many DB values will you get in 8-10ms? I guess you could just add the values as you get them and count the number of times, then after your time limit, 8-10ms, divide the DB sum by the count and display the result. Then wait another 200ms and begin again.
Do I have that right?
Paul