Can Arduino sound reproduce in microseconds at 1-4 kHz?

I just connected an electret microphone to the Arduino, and I would like to try between the 1 kHz and 4 kHz ranges .

I understand that this is limited to machine code and ADC , so I am trying to keep sketch simple.

Is it possible to sample between these frequencies using the sketch below?

const int analogPin = 0;
int ledPin = 13;

void setup() {
    pinMode(ledPin, OUTPUT);
}

void loop() {
    int mn = 1024;
    int mx = 0;
    for (int i = 0; i < 5; ++i) {
        int val = analogRead(analogPin);
        mn = min(mn, val);
        mx = max(mx, val);
    }
    if (mx-mn >= 50) {
        digitalWrite(ledPin, HIGH);
    }
    else {
        digitalWrite(ledPin, LOW);
    }
}
+5
source share
2 answers

Arduino - , . , . , Arduino Uno/Nano, Due.

, ( ) 13 . ADC ( MCU) , 2. , 16 0,6 . . . , , . , - , , 100 . 126 . . .

, 50 - 200 . Arduino ( wiring.c) 128:

sbi(ADCSRA, ADPS2);
sbi(ADCSRA, ADPS1);
sbi(ADCSRA, ADPS0);

, 128 * 13 = 1764 , 10K . , , readAnalog() - , . , : , readAnalog(), . , 4Khz, , 1,5k /, . : , , , 2 , .


, , 0-5 , , analogRead(). , , , .


, , , . ? , analogRead(), : Arduino , .

+1

, , , ADC 10k- , 5 . , , .

.

, Arduino , DigitalRead/Write, . - , DigitalRead/Write, , .

, , AnalogRead, .

, :

  • - (JeeLabs)

  • ++ (JeeLabs)

0

All Articles