//Teensy 3.2, Teensyduino 1.36, Arduino 1.6.12
//USB Type: Audio
//96 MHz optimize speed (overclock)
//Libraries
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <TimeLib.h>
//BC127 I/O
#define play_pause 4
#define streaming 5
//BC127 I2S Pins
#define bt_clk 9
#define bt_out 13
#define bt_sync 23
//VREG pin
#define vreg 15
//LEDs
#define blue_led 20
//SparkFun Navigation Switch
#define steady_state 18
#define activate 19
//Switch activation/verification
int switch_state;
//Switch press debounce
long t = 0;
long debounce = 1000;
//Audio streaming
AudioInputI2Sslave i2s_slave1; //xy=105,63
AudioOutputUSB usb1; //xy=439,164
AudioConnection patchCord3(i2s_slave1, 0, usb1, 0);
AudioConnection patchCord4(i2s_slave1, 1, usb1, 1);
void setup() {
//Pinmodes
pinMode(steady_state, INPUT_PULLUP);
pinMode(activate, INPUT_PULLUP);
pinMode(streaming, INPUT);
pinMode(vreg, INPUT_PULLUP);
pinMode(play_pause, OUTPUT);
pinMode(blue_led, OUTPUT);
digitalWrite(blue_led,HIGH);
digitalWrite(play_pause, LOW);
//Start serial bus and set rate
Serial.begin(9600);
//Audio Memory Allocation
AudioMemory(100);
}
void loop() {
switch_state = digitalRead(activate);
if (switch_state == HIGH && millis() - t > debounce) {
//Flicker play_pause pin until BC127 is streaming
if (!digitalRead(streaming)) {
while (1) {
digitalWrite(play_pause, HIGH);
digitalWrite(blue_led, LOW);
delay(500);
digitalWrite(play_pause, LOW);
digitalWrite(blue_led, HIGH);
delay(500);
if (digitalRead(streaming)) break;
}
}
t = millis();
}
}