File tree 1 file changed +8
-2
lines changed
libraries/ESP_I2S/examples/Simple_tone
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 24
24
2nd September 2021
25
25
Lucas Saavedra Vaz (lucasssvaz)
26
26
22nd December 2023
27
+ anon
28
+ 28nd December 2024
27
29
*/
28
30
29
31
#include < ESP_I2S.h>
@@ -36,17 +38,19 @@ i2s_data_bit_width_t bps = I2S_DATA_BIT_WIDTH_16BIT;
36
38
i2s_mode_t mode = I2S_MODE_STD;
37
39
i2s_slot_mode_t slot = I2S_SLOT_MODE_STEREO;
38
40
39
- const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave
41
+ const int halfWavelength = (sampleRate / frequency / 2 ); // half wavelength of square wave
40
42
41
43
int32_t sample = amplitude; // current sample value
42
- int count = 0 ;
44
+ unsigned int count = 0 ;
43
45
44
46
I2SClass i2s;
45
47
46
48
void setup () {
47
49
Serial.begin (115200 );
48
50
Serial.println (" I2S simple tone" );
49
51
52
+ i2s.setPins (5 , 25 , 26 );
53
+
50
54
// start I2S at the sample rate with 16-bits per sample
51
55
if (!i2s.begin (mode, sampleRate, bps, slot)) {
52
56
Serial.println (" Failed to initialize I2S!" );
@@ -61,7 +65,9 @@ void loop() {
61
65
}
62
66
63
67
i2s.write (sample); // Right channel
68
+ i2s.write (sample >> 8 );
64
69
i2s.write (sample); // Left channel
70
+ i2s.write (sample >> 8 );
65
71
66
72
// increment the counter for the next sample
67
73
count++;
You can’t perform that action at this time.
0 commit comments