Skip to content

Commit

Permalink
Add example for NRF52
Browse files Browse the repository at this point in the history
  • Loading branch information
TMRh20 committed Dec 17, 2023
1 parent 9aaf553 commit e77aa64
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/NRF52_PDM_PWMTest/NRF52_PDM_PWMTest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <AutoAnalogAudio.h>
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
}
10 changes: 10 additions & 0 deletions src/AutoAnalogAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,16 @@ class AutoAnalog
* for playback on any PC or audio device.
*/

/**
* @example NRF52_PDM_PWMTest.ino
* <b>For Arduino XIAO 52840 Sense</b><br>
*
* 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
*
Expand Down

0 comments on commit e77aa64

Please sign in to comment.