Skip to content

Commit dd70e34

Browse files
committed
made some fix to the ESP32 I2S simple tone example
1 parent 5ba4c21 commit dd70e34

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

libraries/ESP_I2S/examples/Simple_tone/Simple_tone.ino

+10-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
2nd September 2021
2525
Lucas Saavedra Vaz (lucasssvaz)
2626
22nd December 2023
27+
anonZ
28+
10nd February 2025
2729
*/
2830

2931
#include <ESP_I2S.h>
@@ -36,21 +38,24 @@ i2s_data_bit_width_t bps = I2S_DATA_BIT_WIDTH_16BIT;
3638
i2s_mode_t mode = I2S_MODE_STD;
3739
i2s_slot_mode_t slot = I2S_SLOT_MODE_STEREO;
3840

39-
const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave
41+
const int halfWavelength = (sampleRate / frequency / 2); // half wavelength of square wave
4042

4143
int32_t sample = amplitude; // current sample value
42-
int count = 0;
44+
unsigned int count = 0;
4345

4446
I2SClass i2s;
4547

4648
void setup() {
4749
Serial.begin(115200);
4850
Serial.println("I2S simple tone");
4951

52+
i2s.setPins(5, 25, 26);
53+
5054
// start I2S at the sample rate with 16-bits per sample
5155
if (!i2s.begin(mode, sampleRate, bps, slot)) {
5256
Serial.println("Failed to initialize I2S!");
53-
while (1); // do nothing
57+
while (1)
58+
; // do nothing
5459
}
5560
}
5661

@@ -61,7 +66,9 @@ void loop() {
6166
}
6267

6368
i2s.write(sample); // Right channel
69+
i2s.write(sample >> 8);
6470
i2s.write(sample); // Left channel
71+
i2s.write(sample >> 8);
6572

6673
// increment the counter for the next sample
6774
count++;

0 commit comments

Comments
 (0)