For Arduino Due
Audio Relay & Peripheral Test Example:
This example demonstrates how to manage incoming and outgoing audio streams using the AAAudio library and nrf24l01+ radio modules on Arduino Due.
- This example uses the onboard DAC to play the incoming audio data via DAC0
- The ADC is used to sample the DAC0 pin, and the data is made available
- The data is re-broadcast over the radios
- Incoming radio data can be directly re-broadcast, but this example is a test of all peripherals
- Note
- This code depends on radio.h located in the same directory.
#define radioCEPin 7
#define radioCSPin 8
#define radioInterruptPin 2
#include <RF24.h>
#include "myRadio.h"
void DACC_Handler(void) {
}
void setup() {
Serial.begin(115200);
Serial.println("Analog Audio Begin");
#if defined (ARDUINO_AVR)
#endif
setupRadio();
}
uint32_t dispTimer = 0;
void loop() {
if (millis() - dispTimer > 3000) {
dispTimer = millis();
#if !defined (ARDUINO_ARCH_AVR)
TcChannel * t = &(TC0->TC_CHANNEL)[0];
TcChannel * tt = &(TC0->TC_CHANNEL)[1];
Serial.print("Ch0:");
Serial.println(t->TC_RC);
Serial.print("Ch1:");
Serial.println(tt->TC_RC);
#else
Serial.print("Ch0/1:");
Serial.println(ICR1);
#endif
}
}
uint32_t dynSampleRate = 0;
void RX() {
if (radio.available(&pipeNo)) {
if (pipeNo == 2) {
radio.read(&dynSampleRate, 4);
} else {
#if !defined (ARDUINO_ARCH_AVR)
radio.stopListening();
#endif
#if !defined (ARDUINO_ARCH_AVR)
radio.startFastWrite(&aaAudio.
adcBuffer, 32, 1);
#endif
}
} else {
radio.txStandBy();
radio.startListening();
}
}
void setSampleRate(uint32_t sampRate=0, bool stereo=false)
uint8_t adcBuffer[MAX_BUFFER_SIZE]
uint8_t dacBuffer[MAX_BUFFER_SIZE]
void getADC(uint32_t samples=MAX_BUFFER_SIZE)
void begin(uint8_t enADC, uint8_t enDAC, uint8_t _useI2S=0)
void feedDAC(uint8_t dacChannel=0, uint32_t samples=MAX_BUFFER_SIZE, bool startInterrupts=false)