File tree 1 file changed +10
-3
lines changed
libraries/ESP_I2S/examples/Simple_tone
1 file changed +10
-3
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
+ anonZ
28
+ 10nd February 2025
27
29
*/
28
30
29
31
#include < ESP_I2S.h>
@@ -36,21 +38,24 @@ 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!" );
53
- while (1 ); // do nothing
57
+ while (1 )
58
+ ; // do nothing
54
59
}
55
60
}
56
61
@@ -61,7 +66,9 @@ void loop() {
61
66
}
62
67
63
68
i2s.write (sample); // Right channel
69
+ i2s.write (sample >> 8 );
64
70
i2s.write (sample); // Left channel
71
+ i2s.write (sample >> 8 );
65
72
66
73
// increment the counter for the next sample
67
74
count++;
You can’t perform that action at this time.
0 commit comments