Quellcode durchsuchen

pre-delivery version

todo :
-wifi udp communication
-use config.txt on sd to get IP
Etienne Landon vor 8 Jahren
Ursprung
Commit
3ca9bdd661
1 geänderte Dateien mit 59 neuen und 18 gelöschten Zeilen
  1. 59 18
      I_Mihalache_AudioPlayer.ino

+ 59 - 18
I_Mihalache_AudioPlayer.ino

@@ -11,17 +11,17 @@
  * 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
+AudioPlaySdWav           LoopPlayer;     //xy=152,429   LOOP
+AudioPlaySdWav           PresencePlayer;     //xy=153,217   PRESENCE
+AudioPlaySdWav           WaitPlayer;     //xy=155,307   WAIT
 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          patchCord1(LoopPlayer, 0, mixer2, 0);
+AudioConnection          patchCord2(PresencePlayer, 0, mixer1, 0);
+AudioConnection          patchCord3(WaitPlayer, 0, mixer1, 1);
 AudioConnection          patchCord4(mixer1, 0, i2s1, 0);
 AudioConnection          patchCord5(mixer1, rms1);
 AudioConnection          patchCord6(mixer2, 0, i2s1, 1);
@@ -29,11 +29,14 @@ 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"
+#define LOOP_WAV "LOOP.WAV"
+#define PRESENCE_WAV "PRESENCE.WAV"
+#define WAIT_WAV "PRESENCE.WAV"
+
+int WAIT_TIME=30000 ;
 
 bool presence ;
+uint32_t LastPresence ;
  
 // Use these with the Teensy Audio Shield
 #define SDCARD_CS_PIN    10
@@ -93,7 +96,7 @@ void playFile(const char *filename)
 {
   Serial.print("Playing file: ");
   Serial.println(filename);
-  playSdWav1.play(filename);
+  PresencePlayer.play(filename);
   // A brief delay for the library read WAV info
   delay(5);
 
@@ -117,18 +120,56 @@ bool checkPresence(int Pin1, int Pin2) {
 }
 void loop() {
   
-   // filenames are always uppercase 8.3 format
-  if (!playSdWav1.isPlaying()) {
-    playFile(LOOP_WAV); 
+  // LOOP FILE
+  if (!LoopPlayer.isPlaying()) {
+    Serial.println("Playing LOOP file");
+    LoopPlayer.play(LOOP_WAV);
+    // A brief delay for the library read WAV info
+    delay(10); 
   }
+
+  // PRESENCE FILE
   presence = checkPresence(16, 20);
+  //printLDR();
   //Serial.println(presence);
-  if (presence && !playSdWav2.isPlaying() ) { 
-  Serial.println("Playing presence file");
-  playSdWav2.play(PRESENCE_WAV);
-  delay(5);
+
+  //PRESENCE DETECTED
+  if (presence ) { 
+    LastPresence = millis() ; 
+    
+    if (!PresencePlayer.isPlaying()) {
+      //stop WAIT_WAV if playing
+      if (WaitPlayer.isPlaying()) {
+          //fade out WaitPlayer
+          Serial.println("Fade out Wait file");
+          for (float fadeRamp ; fadeRamp < 100 ; fadeRamp++ ) {
+            mixer1.gain(1, 1.0 - fadeRamp/100) ;
+          }
+          WaitPlayer.stop() ;
+          mixer1.gain (1, 1.0); // set volume for next play
+          delay(2000) ; 
+        
+      }
+      PresencePlayer.play(PRESENCE_WAV) ;
+      delay(15);
+      Serial.println("Playing presence file");
+    }   
+    
+    // if presence and playing, don't do anything
   }
+  else if (!presence ) {
+    
+    if (PresencePlayer.isPlaying()) {
+      //what if presence gone while playing ?
+    }
+    if ( (millis() - LastPresence > WAIT_TIME) && !WaitPlayer.isPlaying() && !PresencePlayer.isPlaying()) {
+      WaitPlayer.play(WAIT_WAV);
+      Serial.println("Playing wait file");
+      delay(10);
+    }
+  }
+
   ESPSerial();
-//  delay(100);
+  delay(100);
 }