Code:
#include <Audio.h> // Include the Teensy Audio Library
#include <Wire.h> // Include the Teensy I2C Library
#include <Metro.h> // Include the Metro library for triggering functions based on time
AudioInputI2S audioIn; //xy=178,263
AudioOutputI2S audioOut; //xy=539,261
AudioMixer4 mixer1; //xy=407,264
AudioSynthWaveformSine sine1;
// Uncomment these to test the system (just a straight passthrough)
//AudioConnection patchCord1(audioIn, 0, audioOut, 0);
//AudioConnection patchCord2(audioIn, 1, audioOut, 1);
// Uncomment this and audio will be constant
//AudioConnection patchCord3(audioIn, 1, mixer1, 1);
// Uncomment this and audio toggles (as expected - but beware the sine noise)
//AudioConnection patchCord4(sine1, 0, mixer1, 1);
// Leave this one connected
AudioConnection patchCord6(mixer1, 0, audioOut, 1);
// Dynamic patchcord
AudioConnection* pANAI0_ANAO0;
AudioControlSGTL5000 sgtl5000_1; //xy=340,426
// GUItool: end automatically generated code
#define LED_HB 5 // Pin with LED for heartbeat
// Variables
int LED_HB_State = LOW; // Var to hold state of heartbeat LED
// Instantiate a Metro object
Metro Int500msMetro = Metro(500); // Set 500msMetro to return true every half second
// Functions Below
// ---------------
void audio_in_setup()
{
pANAI0_ANAO0 = new AudioConnection(audioIn, 0, audioOut, 0);
// Both of the following options work (depending on the other things connected)
// pANAI0_ANAO0 -> disconnect();
// delete pANAI0_ANAO0; // -> disconnect();
}
// Ignore this function for now - Not used
//void audio_in_toggle(void)
//{
// if(pANAI0_ANAO0)
// {
// pANAI0_ANAO0 -> disconnect();
// Serial.println("Disconnected");
// }
// else
// {
// pANAI0_ANAO0 -> disconnect();
// Serial.println("Connected");
// }
//}
void audio_in_disconnect(void)
{
pANAI0_ANAO0 -> disconnect();
Serial.println("Disconnected");
}
void audio_in_connect(void)
{
pANAI0_ANAO0 -> connect();
Serial.println("Connected");
}
void setup() {
Serial.begin(115200);
delay(500);
Serial.printf("Starting setup...\n");
AudioMemory(12); // Audio memory for audio library
sgtl5000_1.enable(); // Enable the audio shield
sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN); // Set the input to line in
sgtl5000_1.volume(0.5); // Initial volume level for headphone out
audio_in_setup();
sine1.amplitude(0.25);
sine1.frequency(500);
Serial.printf("Setup complete.\n");
}
void loop() {
// 500msMetro object - a pseudo half second interrupt
if (Int500msMetro.check() == 1) // Check if the object has passed its interval
{
// Heartbeat LED
if (LED_HB_State == LOW)
{
LED_HB_State = HIGH;
audio_in_connect();
}
else
{
LED_HB_State = LOW;
audio_in_disconnect();
}
digitalWrite(LED_HB, LED_HB_State);
// audio_in_toggle();
}
}
I copied and pasted that from the DropBox.
Thank you!!!