#include #include #include #include #include /* SdWav1 : sample voix | * SdWav2 : sample attente |-> mix1 -> Lout & RMS1 * * SdWav3 : sample ambiance -> mix2 -> Rout & RMS2 */ // GUItool: begin automatically generated code AudioPlaySdWav playSdWav3; //xy=152,429 AudioPlaySdWav playSdWav1; //xy=153,217 AudioPlaySdWav playSdWav2; //xy=155,307 AudioMixer4 mixer1; //xy=572,215 AudioMixer4 mixer2; //xy=579,344 AudioAnalyzeRMS rms1; //xy=875,315 AudioOutputI2S i2s1; //xy=876,225 AudioAnalyzeRMS rms2; //xy=876,365 AudioConnection patchCord1(playSdWav3, 0, mixer2, 0); AudioConnection patchCord2(playSdWav1, 0, mixer1, 0); AudioConnection patchCord3(playSdWav2, 0, mixer1, 1); AudioConnection patchCord4(mixer1, 0, i2s1, 0); AudioConnection patchCord5(mixer1, rms1); AudioConnection patchCord6(mixer2, 0, i2s1, 1); AudioConnection patchCord7(mixer2, rms2); AudioControlSGTL5000 sgtl5000_1; //xy=573,537 // GUItool: end automatically generated code #define LOOP_WAV "SDTEST1.WAV" #define PRESENCE_WAV "SDTEST2.WAV" #define WAIT_WAV "SDTEST3.WAV" bool presence ; // Use these with the Teensy Audio Shield #define SDCARD_CS_PIN 10 #define SDCARD_MOSI_PIN 7 #define SDCARD_SCK_PIN 14 void ESPSerial(){ // Send bytes from ESP8266 -> Teensy to Computer bool printLine ; while ( Serial1.available() ) { Serial.write( Serial1.read() ); printLine = 1 ; } // if (printLine) {Serial.println("");} printLine = 0; // Send bytes from Computer -> Teensy back to ESP8266 while ( Serial.available() ) { Serial1.write( Serial.read() ); } } void setup() { Serial.begin(115200); Serial1.begin(115200); //LDR digital inputs pinMode(16, INPUT); pinMode(20,INPUT); AudioMemory(16); sgtl5000_1.enable(); sgtl5000_1.lineOutLevel(13); // set output to 3.16 Vpp sgtl5000_1.volume(1); //set volume to maximum SPI.setMOSI(SDCARD_MOSI_PIN); SPI.setSCK(SDCARD_SCK_PIN); if (!(SD.begin(SDCARD_CS_PIN))) { // stop here, but print a message repetitively while (1) { Serial.println("Unable to access the SD card"); delay(500); } } Serial1.println("AT+GMR"); delay(2000); //while (!Serial1.available()) {}; ESPSerial(); Serial.println(""); Serial.println(""); delay(00); } // void playFile(const char *filename) { Serial.print("Playing file: "); Serial.println(filename); playSdWav1.play(filename); // A brief delay for the library read WAV info delay(5); } void printLDR(){ Serial.print(analogRead(A3)); Serial.print(" "); Serial.print(digitalRead(16)); Serial.print(" "); Serial.print(analogRead(A7)); Serial.print(" "); Serial.print(digitalRead(20)); Serial.println(); } bool checkPresence(int Pin1, int Pin2) { bool isPresent = digitalRead(Pin2); //|| digitalRead(Pin2); return isPresent ; } void loop() { // filenames are always uppercase 8.3 format if (!playSdWav1.isPlaying()) { playFile(LOOP_WAV); } presence = checkPresence(16, 20); //Serial.println(presence); if (presence && !playSdWav2.isPlaying() ) { Serial.println("Playing presence file"); playSdWav2.play(PRESENCE_WAV); delay(5); } ESPSerial(); // delay(100); }