Question: #include // include FFT library const int SAMPLES = 128; // number of samples to collect int sample[SAMPLES]; // array to store samples int microphonePin

#include // include FFT library

const int SAMPLES = 128; // number of samples to collect

int sample[SAMPLES]; // array to store samples

int microphonePin = A0; // microphone is connected to A0

void setup() {

Serial.begin(9600); // start serial communication

}

void loop() {

// read microphone input and store it in the sample array

for (int i = 0; i < SAMPLES; i++) {

sample[i] = analogRead(microphonePin);

}

// perform FFT on the sample array

FFT.Windowing(sample, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);

FFT.Compute(sample, SAMPLES, FFT_FORWARD);

FFT.ComplexToMagnitude(sample, SAMPLES);

// set threshold level for loudness

int threshold = 100;

// check if the frequency domain data is above or below the threshold

if (sample[0] > threshold) {

// if above threshold, turn on LED

digitalWrite(LED_BUILTIN, HIGH);

} else {

// if below threshold, turn off LED

digitalWrite(LED_BUILTIN, LOW);

}

}

I can't understand what each line of these codes do. Can you explain me each line in detail?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!