mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
* Fix shell variable comparison without $CI present + '[' = true ']' ./tests/restyle.sh: line 16: [: =: unary operator expected vs. + '[' '' = true ']' * Update to clang-format-18 new opt to skip overly eager macro formatting https://clang.llvm.org/docs/ClangFormatStyleOptions.html#skipmacrodefinitionbody minor changes between 15 and 18 for ide examples reference arduino-ide format is still stuck with 15, though https://github.com/arduino/clang-static-binaries/releases * Pin clang-format in CI recipe not the script itself * style
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
/*
|
|
This example generates a square wave based tone at a specified frequency
|
|
and sample rate. Then outputs the data using the I2S interface to a
|
|
MAX08357 I2S Amp Breakout board.
|
|
|
|
created 17 November 2016
|
|
by Sandeep Mistry
|
|
modified for ESP8266 by Earle F. Philhower, III <earlephilhower@yahoo.com>
|
|
*/
|
|
|
|
#include <I2S.h>
|
|
|
|
const int frequency = 440; // frequency of square wave in Hz
|
|
const int amplitude = 500; // amplitude of square wave
|
|
const int sampleRate = 8000; // sample rate in Hz
|
|
|
|
const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave
|
|
|
|
short sample = amplitude; // current sample value
|
|
int count = 0;
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
Serial.println("I2S simple tone");
|
|
|
|
// start I2S at the sample rate with 16-bits per sample
|
|
if (!I2S.begin(I2S_PHILIPS_MODE, sampleRate, 16)) {
|
|
Serial.println("Failed to initialize I2S!");
|
|
while (1); // do nothing
|
|
}
|
|
}
|
|
|
|
void loop() {
|
|
if (count % halfWavelength == 0) {
|
|
// invert the sample every half wavelength count multiple to generate square wave
|
|
sample = -1 * sample;
|
|
}
|
|
|
|
// write the same sample twice, once for left and once for the right channel
|
|
I2S.write(sample);
|
|
I2S.write(sample);
|
|
|
|
// increment the counter for the next sample
|
|
count++;
|
|
}
|