I have the following code in loop() to collect values from an electret microphone
for(int i=0; i<sampleSize; i++){
analogVal[i]= analogRead(ADC_Pin);
sumOfSquares= sumOfSquares+sq(analogVal[i]);
}
Serial.print("Sum of squares: ");
Serial.print(sumOfSquares);
where sampleSize is an int variable, I've tried numbers from 3 to 1000, which is my desired value. ADC_Pin is an int variable set to be A1 and has been properly initialized through pinMode. analogVal is an int array of size sampleSize.
My circuit appears to be fine because the output produces a reasonable amount of voltage. I've tried eliminating the line with sumOfSquares and just having the first line in the for loop. However, the Serial Monitor hangs and does not display any values. The serial communication is at 9600 bps.
Serial.begin(115200);
[or whatever the data rate is that you have your serial monitor set at] ¶ Anyway, I don't know what the problem is, and if you don't edit your question to include a Minimal, Complete, and Verifiable example of code -- with visible definitions of every variable used, etc -- perhaps nobody else will be able to tell either.analogVal
? What issumOfSquares
? What is thesq()
function? In short: DO NOT POST SNIPPETS LIKE THIS - POST A COMPLETE PROGRAM SO WE CAN SEE THE ENTIRE PROGRAM AND VARIABLE DECLARATIONS.