Example sketch showing how to create an audio digital transmitter with the NRF24 class. Connect a 1Vp-p audio sigal to analog input 0, connected through a 1uF capacitor Works with the nrf24_audio_rx sample receiver The audio quality is poor: dont expect hi-fi!
This code sends about 250 messages per second, each with 32 8 bit samples from analog input 0 It uses the NRF4 in NOACK mode. The receiver never acknowledges or replies Tested on UNO
#include <NRF24.h>
#include <SPI.h>
void setup()
{
Serial.begin(9600);
while (!Serial)
;
Serial.println("NRF24 init failed");
Serial.println("setChannel failed");
Serial.println("setPayloadSize failed");
Serial.println("setRF failed");
analogReference(INTERNAL);
Serial.println("initialised");
}
void loop()
{
uint8_t buf[32];
uint8_t i;
for (i = 0; i < 32; i++)
buf[i] = analogRead(0);
Serial.println("setTransmitAddress failed");
if (!nrf24.
send(buf,
sizeof(buf),
true))
Serial.println("send failed");
Serial.println("waitPacketSent failed");
digitalWrite(3, LOW);
}