מכשיר קשר ESP32 — לדבר בלי אינטרנט

Code for reading and copying

משמיעים צפצוף ראשון

This code is read-only, so it cannot be changed by accident.

audio_test_3x.ino cpp
#include <Arduino.h>
#include <ESP_I2S.h>

constexpr int AMP_BCLK = 26;
constexpr int AMP_LRC = 27;
constexpr int AMP_DIN = 14;
constexpr uint32_t SAMPLE_RATE = 16000;

I2SClass Speaker(I2S_NUM_1);

void setup() {
  Serial.begin(115200);
  Speaker.setPins(AMP_BCLK, AMP_LRC, AMP_DIN);
  if (!Speaker.begin(I2S_MODE_STD, SAMPLE_RATE, I2S_DATA_BIT_WIDTH_16BIT,
                     I2S_SLOT_MODE_MONO, I2S_STD_SLOT_BOTH)) {
    Serial.println("I2S ERROR — check BCLK, LRC and DIN");
    while (true) delay(1000);
  }
  Serial.println("AUDIO TEST READY");
}

void loop() {
  for (int i = 0; i < 4000; ++i) {
    const int16_t sample = (i / 10 % 2) ? 5000 : -5000;
    Speaker.write(&sample, sizeof(sample));
  }
  delay(500);
}