/*
Demo of the audio sweep function.
The user specifies the amplitude,
start and end frequencies (which can sweep up or down)
and the length of time of the sweep.
Modified to use the single DAC on the Teensy 3.1/3.2 and the first DAC on the
Teensy 3.5 or 3.6. The 3.0, 4.0 and 4.1 Teensies do not have a DAC.
Pins: Teensy LC Teensy 3.2 Teensy 3.5/3.6
DAC: A12 A14 A21
*/
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// Define USE_PROPSHIELD if the Teensy uses the prop shield, and we want to
// enable the onboard amplifier. Assume the LC/3.2 will have the propshield,
// but the 3.5/3.6 won't.
#if defined(__MKL26Z64__) || defined(__MK20DX256__)
#define USE_PROPSHIELD 1
#endif
// GUItool: begin automatically generated code (edited by meissner afterwards).
AudioSynthToneSweep tonesweep; //xy=102,174
AudioAmplifier amp; //xy=324,172
AudioOutputAnalog dac; //xy=452,189
AudioConnection patchCord1 (tonesweep, amp);
AudioConnection patchCord2 (amp, 0, dac, 0);
// GUItool: end automatically generated code
const float t_ampx = 0.8;
const int t_lox = 10;
const int t_hix = 22000;
const float t_timex = 10; // Length of time for the sweep in seconds
void setup(void)
{
// Wait for at least 3 seconds for the USB serial connection
Serial.begin (9600);
while (!Serial && millis () < 3000)
;
AudioMemory (8);
amp.gain (0.5f);
// Enable the prop shield speaker
#if USE_PROPSHIELD
pinMode (5, OUTPUT);
digitalWrite (5, HIGH);
#endif
Serial.println("setup done");
if (!tonesweep.play (t_ampx, t_lox, t_hix, t_timex)) {
Serial.println ("ToneSweep - play failed");
while (1)
;
}
// wait for the sweep to end
Serial.println ("Tonesweep up started");
while (tonesweep.isPlaying ())
;
// and now reverse the sweep
Serial.println ("Tonesweep down started");
if (!tonesweep.play (t_ampx, t_hix, t_lox, t_timex)) {
Serial.println("ToneSweep - play failed");
while (1)
;
}
// wait for the sweep to end
while (tonesweep.isPlaying ())
;
Serial.println("Done");
}
void loop(void)
{
}