Added arduino files

This commit is contained in:
BlueFox 2024-06-09 15:18:04 +00:00
parent 2d70af29da
commit 257e54a47c

View File

@ -0,0 +1,65 @@
/**
* @file simple-bt-receiver.ino
* @author Benjamin Burkhardt
* @brief Simple bluetooth receiver built on ESP32 using the AudioTools library
*
* @author Benjamin Burkhardt
* @copyright GPL-3.0-or-later
*
*/
/*
* Based on examples of the AudioTools library (https://github.com/pschatzmann/arduino-audio-tools)
* It was combined out of the input stream in the a2dp-serial and the output stream of the generator-i2s example
* - streams-a2dp-serial.ino - https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-stream/streams-a2dp-serial
* - streams-generator-i2s.ino - https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-stream/streams-generator-i2s
*/
/*
* Used partition scheme: "Minimal SPIFFS"
*/
#include "AudioTools.h"
#include "AudioLibs/A2DPStream.h"
A2DPStream a2dp_in;
CsvOutput<int16_t> out(Serial, 2); // ASCII stream as csv
I2SStream i2s_out; // I2S stream (to external DAC)
StreamCopy copier(i2s_out, a2dp_in); // copy in to out
const char* a2dp_name = "<DIY Speaker's name>";
const bool a2dp_auto_reconnect = true;
// Arduino Setup
void setup(void) {
Serial.begin(115200);
while (!Serial)
;
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
// start I2S
Serial.println("Setting up I2S...");
auto config_i2s = i2s_out.defaultConfig(TX_MODE);
config_i2s.copyFrom(a2dp_in.audioInfoOut());
i2s_out.begin(config_i2s);
Serial.println("Set up I2S!");
// start the bluetooth audio receiver
Serial.println("Setting up A2DP...");
auto config_a2dp = a2dp_in.defaultConfig(RX_MODE);
config_a2dp.name = a2dp_name;
config_a2dp.auto_reconnect = a2dp_auto_reconnect;
a2dp_in.begin(config_a2dp);
Serial.println("Set up A2DP!");
Serial.println("Started!");
}
// Arduino loop
void loop() {
copier.copy();
}