wrong demo!
This commit is contained in:
parent
6ffe240e13
commit
99fc8760c7
2 changed files with 47 additions and 53 deletions
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
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.
|
||||
|
||||
Circuit:
|
||||
* Arduino/Genuino Zero, MKRZero or MKR1000 board
|
||||
* MAX08357:
|
||||
* GND connected GND
|
||||
* VIN connected 5V
|
||||
* LRC connected to pin 0 (Zero) or pin 3 (MKR1000, MKRZero)
|
||||
* BCLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKRZero)
|
||||
* DIN connected to pin 9 (Zero) or pin A6 (MKR1000, MKRZero)
|
||||
|
||||
created 17 November 2016
|
||||
by Sandeep Mistry
|
||||
*/
|
||||
|
||||
#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(9600);
|
||||
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++;
|
||||
}
|
||||
47
Adafruit_UDA1334A/SineTone/SineTone.ino
Normal file
47
Adafruit_UDA1334A/SineTone/SineTone.ino
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
This example generates a sine wave based tone at a specified frequency
|
||||
and sample rate. Then outputs the data using the I2S interface.
|
||||
|
||||
Public Domain
|
||||
*/
|
||||
|
||||
#include <I2S.h>
|
||||
|
||||
#define FREQUENCY 440 // frequency of sine wave in Hz
|
||||
#define AMPLITUDE 10000 // amplitude of sine wave
|
||||
#define SAMPLERATE 44100 // sample rate in Hz
|
||||
|
||||
int16_t sinetable[SAMPLERATE / FREQUENCY];
|
||||
uint32_t sample = 0;
|
||||
|
||||
#define PI 3.14159265
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("I2S sine wave 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
|
||||
}
|
||||
|
||||
// fill in sine wave table
|
||||
for (uint16_t s=0; s < (SAMPLERATE / FREQUENCY); s++) {
|
||||
sinetable[s] = sin(2.0 * PI * s / (SAMPLERATE/FREQUENCY)) * AMPLITUDE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
if (sample == (SAMPLERATE / FREQUENCY)) {
|
||||
sample = 0;
|
||||
}
|
||||
|
||||
// write the same sample twice, once for left and once for the right channel
|
||||
I2S.write((int16_t) sinetable[sample]); // We'll just have same tone on both!
|
||||
I2S.write((int16_t) sinetable[sample]);
|
||||
|
||||
// increment the counter for the next sample in the sine wave table
|
||||
sample++;
|
||||
}
|
||||
Loading…
Reference in a new issue