snapshot
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
# PWM Output Test
|
||||
|
||||
This is a simple basic test for the PWM output.
|
||||
|
||||
We just send a generated sine wave to some defined pins and expect to hear some audio signal.
|
||||
|
||||
|
||||
### Output Device: Piezo Electric Element
|
||||
|
||||
To test the output I am using a piezo electric element
|
||||
|
||||

|
||||
|
||||
You can also use some simple earphones
|
||||
|
||||

|
||||
|
||||
|
||||
It should also be possible to connect a headphone to the output pins...
|
||||
|
||||
|
||||
The pins depend on the Processor:
|
||||
|
||||
|
||||
| PIEZO | ESP32 | RPI Pico | MBED | UNO R4 |
|
||||
| --------| -------------|---------------|--------------|-------------|
|
||||
| + | GPIO4/GPIO5 | GPIO2/GPIO3 | GPIO2/GPIO3 | GPIO2/GPIO4 |
|
||||
| - | GND | GND | GND | GND |
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @file streams-generator-pwm.ino
|
||||
* @author Phil Schatzmann
|
||||
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-stream/streams-generator-pwm/README.md
|
||||
* @author Phil Schatzmann
|
||||
* @copyright GPLv3
|
||||
*/
|
||||
|
||||
#include "AudioTools.h"
|
||||
|
||||
AudioInfo info(8000, 1, 16);
|
||||
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
|
||||
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
|
||||
PWMAudioOutput pwm;
|
||||
StreamCopy copier(pwm, sound); // copy in to out
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
|
||||
|
||||
// setup sine wave
|
||||
sineWave.begin(info, N_B4);
|
||||
|
||||
// setup PWM output
|
||||
auto config = pwm.defaultConfig();
|
||||
config.copyFrom(info);
|
||||
//config.resolution = 8; // must be between 8 and 11 -> drives pwm frequency (8 is default)
|
||||
// alternative 1
|
||||
//config.start_pin = 3;
|
||||
// alternative 2
|
||||
//int pins[] = {3};
|
||||
// alternative 3
|
||||
//Pins pins = {3};
|
||||
//config.setPins(pins);
|
||||
pwm.begin(config);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
copier.copy();
|
||||
}
|
||||
Reference in New Issue
Block a user