diff --git a/examples/NRF52_PDM_PWMTest/NRF52_PDM_PWMTest.ino b/examples/NRF52_PDM_PWMTest/NRF52_PDM_PWMTest.ino new file mode 100644 index 0000000..cede1b0 --- /dev/null +++ b/examples/NRF52_PDM_PWMTest/NRF52_PDM_PWMTest.ino @@ -0,0 +1,23 @@ +#include +AutoAnalog aaAudio; + +// REQUIRES MBed Enabled Core for NRF52 (XIAO 52840 Sense) + +void setup() { + + //Startup the PDM Microphone on pin A0 and PWM(pseudo DAC) on pin 5 + aaAudio.begin(1, 1); + aaAudio.autoAdjust = 0; + aaAudio.adcBitsPerSample = 16; // 16-bit audio at 16khz is the default on NRF52 and cannot be modified currently (in progress) + aaAudio.setSampleRate(16000); + +} + +void loop() { + + aaAudio.getADC(320); // Get 320 Samples from the ADC + for (int i = 0; i < 320; i++) { // Copy them into the DAC Buffer and change from signed to unsigned ( + 0x8000) + aaAudio.dacBuffer16[i] = (uint16_t)(aaAudio.adcBuffer16[i] + 0x8000); + } + aaAudio.feedDAC(320); // Feed the DAC with the ADC data +} diff --git a/src/AutoAnalogAudio.h b/src/AutoAnalogAudio.h index d84ed69..b0fb8e8 100644 --- a/src/AutoAnalogAudio.h +++ b/src/AutoAnalogAudio.h @@ -418,6 +418,16 @@ class AutoAnalog * for playback on any PC or audio device. */ +/** + * @example NRF52_PDM_PWMTest.ino + * For Arduino XIAO 52840 Sense
+ * + * Recording (pin A0) and playback (pin 5) + * + * This example demonstrates recording and playback on a single device + * using PDM microphone and PWM output + */ + /** * @mainpage Automatic Analog Audio Library for Arduino *