Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Can't get 8th WAV File to play

  1. #1

    Can't get 8th WAV File to play

    Could someone please help me figure out why I can't get my eighth Wave file to play in this code? The first seven play perfectly (from SD). When I add the eighth (pinMode(buttonPin8, INPUT_PULLUP) I lose all the audio from all pins. The pins are detected as being activated because they print in my serial monitor, but there is no sound. I'm not sure how to fix my code. I am ultimately trying to include more wave files in my code, each activated with a unique pin, but I can't get beyond seven.

    I've tried the SamplePlayer code, but do not have enough RAM on the Teensy board for the sound files.

    I've also tried to play from flash, and added a flash chip to my Teensy audio board, but I can't figure out how to write that code.

    I am using Windows 8.1, Teensy 3.5 and the Teensy Audio Shield.

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <Bounce.h>
    
    // How many leds are in the strip?
    //const int numled = 77;
    //const int numled = 10;
    
    // Data pin that led data will be written out over
    const int pin = 1; 
    
    const int buttonPin1 = 2;
    Bounce pushbutton1 = Bounce(buttonPin1, 20);
    const int buttonPin2 = 3;
    Bounce pushbutton2 = Bounce(buttonPin2, 20);
    const int buttonPin3 = 4;
    Bounce pushbutton3 = Bounce(buttonPin3, 20);
    const int buttonPin4 = 5;
    Bounce pushbutton4 = Bounce(buttonPin4, 20);
    const int buttonPin5 = 6;
    Bounce pushbutton5 = Bounce(buttonPin5, 20);
    const int buttonPin6 = 7;
    Bounce pushbutton6 = Bounce(buttonPin6, 20);
    const int buttonPin7 = 8;
    Bounce pushbutton7 = Bounce(buttonPin7, 20);
    const int buttonPin8 = 9;                                //New line trying to get 8th note, does not crash program
    Bounce pushbutton8 = Bounce(buttonPin8, 20);             //New line trying to get 8th note, does not crash program
    
    
    // GUItool: begin automatically generated code
    AudioPlaySdWav           playSdWav1;     //xy=305,113
    AudioPlaySdWav           playSdWav2;     //xy=324,180
    AudioMixer4              mixer1;         //xy=523,163
    AudioOutputI2S           i2s1;           //xy=729,205
    AudioConnection          patchCord1(playSdWav1, 0, mixer1, 0);
    AudioConnection          patchCord2(playSdWav2, 0, mixer1, 1);
    AudioConnection          patchCord3(mixer1, 0, i2s1, 0);
    AudioConnection          patchCord4(mixer1, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=536,299
    // GUItool: end automatically generated code
    
    void setup() {
      delay(200);
       // initialize the pushbutton pin as input:
      pinMode(buttonPin1, INPUT_PULLUP);
      pinMode(buttonPin2, INPUT_PULLUP);
      pinMode(buttonPin3, INPUT_PULLUP);
      pinMode(buttonPin4, INPUT_PULLUP);
      pinMode(buttonPin5, INPUT_PULLUP);
      pinMode(buttonPin6, INPUT_PULLUP);
      pinMode(buttonPin7, INPUT_PULLUP);
      //pinMode(buttonPin8, INPUT_PULLUP);                   //New line trying to get 8th note to work, uncommenting this line STOPS all audio
      
      AudioMemory(12);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
      SPI.setMOSI(7);
      SPI.setSCK(14);
      if (!(SD.begin(BUILTIN_SDCARD))) {
        while (1) {
            delay(400);
        }
      }
    }
    void loop() {
      
      pushbutton1.update();
      if (pushbutton1.fallingEdge()) {
        playSdWav1.play("C.wav");
        Serial.println("C"); 
      }
      pushbutton2.update();
      if (pushbutton2.fallingEdge()) {
        playSdWav1.play("D.wav");
        Serial.println("D"); 
      }
      pushbutton3.update();
      if (pushbutton3.fallingEdge()) {
        playSdWav1.play("E.wav");
        Serial.println("E"); 
      }
      pushbutton4.update();
      if (pushbutton4.fallingEdge()) {
        playSdWav1.play("F.wav");
        Serial.println("F"); 
       }
      pushbutton5.update();
      if (pushbutton5.fallingEdge()) {
        playSdWav2.play("G.wav");
        Serial.println("G"); 
      }
      pushbutton6.update();
      if (pushbutton6.fallingEdge()) {
        playSdWav2.play("A.wav");
        Serial.println("A"); 
       }
     pushbutton7.update();
      if (pushbutton7.fallingEdge()) {
        playSdWav2.play("B.wav");
        Serial.println("B");  
      }
      if ( playSdWav1.isPlaying() == 0 ) {
        delay(100);
      if (playSdWav2.isPlaying() == 0 ) {
             }
         }
       }

  2. #2
    Senior Member
    Join Date
    Nov 2017
    Location
    Belgium
    Posts
    152
    Pin 9 is used by the audio shield for the BLCK signal. Try another pin not used by the audioshield like 16 or so.
    see: https://www.pjrc.com/store/teensy3_audio.html

  3. #3
    Neurofun, Thanks, it works!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •