esp_ble_headphones/headphones/headphone_master/headphone_master.ino
2025-05-24 13:01:43 +03:00

38 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <Arduino.h>
#include "BluetoothA2DPSink.h"
#include <esp_now.h>
#include <WiFi.h>
BluetoothA2DPSink a2dp_sink;
uint8_t slave_mac[] = {0x24, 0x6F, 0x28, 0xXX, 0xXX, 0xXX}; // MAC-адрес второго наушника (Slave)
void audio_data_callback(const uint8_t *data, uint32_t length) {
// Разделяем стереоданные на левый и правый канал
// Отправляем правый канал на Slave
esp_now_send(slave_mac, data, length);
}
void setup() {
Serial.begin(115200);
// Настройка I2S
i2s_pin_config_t pin_config = {26, 25, 22, I2S_PIN_NO_CHANGE};
a2dp_sink.set_pin_config(pin_config);
// Настройка ESP-NOW
WiFi.mode(WIFI_STA);
esp_now_init();
esp_now_peer_info_t peerInfo = {};
memcpy(peerInfo.peer_addr, slave_mac, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
esp_now_add_peer(&peerInfo);
// A2DP с коллбэком
a2dp_sink.set_stream_reader(audio_data_callback, false);
a2dp_sink.start("ESP32_TWS_Master");
}
void loop() {}