File tree 3 files changed +160
-129
lines changed
3 files changed +160
-129
lines changed Original file line number Diff line number Diff line change 20
20
const int frequency = 440 ; // frequency of square wave in Hz
21
21
const int amplitude = 500 ; // amplitude of square wave
22
22
const int sampleRate = 8000 ; // sample rate in Hz
23
+ const int bps = 16 ;
23
24
24
25
const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave
25
26
@@ -31,14 +32,14 @@ void setup() {
31
32
Serial.println (" I2S simple tone" );
32
33
33
34
// start I2S at the sample rate with 16-bits per sample
34
- if (!I2S.begin (I2S_PHILIPS_MODE, sampleRate, 16 )) {
35
+ if (!I2S.begin (I2S_PHILIPS_MODE, sampleRate, bps )) {
35
36
Serial.println (" Failed to initialize I2S!" );
36
37
while (1 ); // do nothing
37
38
}
39
+ I2S.setDataOutPin (26 );
38
40
}
39
41
40
42
void loop () {
41
- if (I2S.availableForWrite () >= 2 ){
42
43
if (count % halfWavelength == 0 ) {
43
44
// invert the sample every half wavelength count multiple to generate square wave
44
45
sample = -1 * sample;
@@ -50,5 +51,4 @@ void loop() {
50
51
51
52
// increment the counter for the next sample
52
53
count++;
53
- }
54
54
}
You can’t perform that action at this time.
0 commit comments