Skip to content

Commit

Permalink
Update Simple_tone.ino
Browse files Browse the repository at this point in the history
Fixed I2S tone issue.
  • Loading branch information
greenyleaf authored Dec 28, 2024
1 parent 9eb7dc6 commit 6ec3ebc
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit 6ec3ebc

Please sign in to comment.