Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the I2S Simple_tone.ino #10788

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions libraries/ESP_I2S/examples/Simple_tone/Simple_tone.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
2nd September 2021
Lucas Saavedra Vaz (lucasssvaz)
22nd December 2023
anon
28nd December 2024
*/

#include <ESP_I2S.h>
Expand All @@ -36,17 +38,19 @@ i2s_data_bit_width_t bps = I2S_DATA_BIT_WIDTH_16BIT;
i2s_mode_t mode = I2S_MODE_STD;
i2s_slot_mode_t slot = I2S_SLOT_MODE_STEREO;

const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave
const int halfWavelength = (sampleRate / frequency / 2); // half wavelength of square wave

int32_t sample = amplitude; // current sample value
int count = 0;
unsigned int count = 0;

I2SClass i2s;

void setup() {
Serial.begin(115200);
Serial.println("I2S simple tone");

i2s.setPins(5, 25, 26);

// start I2S at the sample rate with 16-bits per sample
if (!i2s.begin(mode, sampleRate, bps, slot)) {
Serial.println("Failed to initialize I2S!");
Expand All @@ -61,7 +65,9 @@ void loop() {
}

i2s.write(sample); // Right channel
i2s.write(sample >> 8);
i2s.write(sample); // Left channel
i2s.write(sample >> 8);

// increment the counter for the next sample
count++;
Expand Down
Loading