Still trying with this keypad door lock with sound

i keep giving up and coming back to this. sadly i just do not know what i have to do, to make it do what i want it to do… to put it bluntly. i honestly do not even know if it can support it.

i want to make a keypad lock. with audio and pin output (multiple sound files being played each time a wrong code is entered up to say 3 or 4 times until a pin out can trigger an alarm)

i am using a Arduino Due with Ethernet shield (with built in SD card reader for the sound files)

i have got the keypad working how i want it, i have not however managed to get the Due to actually “play” sound. it always comes out sounding strange (stuttering), even though it is the correct bit rate and frequency.

i really am at whits end with this, i cant find any local arduino enthusiasts or pretty much anyone able or willing to help me out on this.

questions:

will the Due… Do this. is it capable of playing a sound and at the same time triggering a pin high?

with what mess of a script i have, could some one on here tell me what i can do to make it do what i want it to do?

should i just give up with these controllers and just build the damn thing manually making each pin out trigger individual sound boards (each board with one sound recorded on it).

here is what i am working with. as you can see pin 12 to 14 are where i have started to give up with the arduino playing sound and decided to go with individual sound boards.

#include <Password.h>
#include <Keypad.h>
#include <SD.h>
#include <SPI.h>
#include <Audio.h>

Password password = Password( "0" );
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'A', '0', 'B'}
};
byte rowPins[ROWS] = { 43, 44, 45, 46 };
byte colPins[COLS] = { 40, 41, 42 };

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int ledPin =  10;
int maxnum = 3;
int count = 0;

void setup() {
  //pinMode(22, OUTPUT);  //orange "working" light
  pinMode(10, OUTPUT); //red "access denied" light
  pinMode(22, OUTPUT); //green "access granted" light
  pinMode(12, OUTPUT); //sound access denied 2
  pinMode(13, OUTPUT); //sound access denied 3
  pinMode(14, OUTPUT); //sound access denied 1

  keypad.addEventListener(keypadEvent);

  // debug output at 9600 baud
  Serial.begin(9600);

  // setup SD-card
  Serial.print("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.println(" failed!");
    return;
  }
  Serial.println(" done.");
  // hi-speed SPI transfers
  SPI.setClockDivider(4);

  // 44100Khz stereo => 88200 sample rate
  // 100 mSec of prebuffering.
  Audio.begin(88200, 100);


}

void loop() {
  keypad.getKey();


  int count = 0;

}
void keypadEvent(KeypadEvent eKey) {
  switch (keypad.getState()) {
    case PRESSED:

      switch (eKey) {
        case 'A': checkPassword(); delay(1); break;
        case 'B': password.reset(); delay(1); break;
        default: password.append(eKey); delay(1);
      }
  }
}
void checkPassword() {


  //access granted
  if (password.evaluate()) {

 

    // open wave file from sdcard
    File myFile = SD.open("ready1.wav");
    if (!myFile) {
      // if the file didn't open, print an error and stop
      Serial.println("error opening ready1.wav");
      while (true);
    }
       Serial.print("access granted");
    count = 0;
    password.reset();
   // digitalWrite(22, HIGH);
    //delay(300);
    //digitalWrite(22, LOW);
    digitalWrite(22, HIGH);
    delay(1000);
    digitalWrite(22, LOW);
    
    const int S = 1024; // Number of samples to read in block
    short buffer[S];

    Serial.print("Playing and unlocking");
    // until the file is not finished
    while (myFile.available()) {
      // read from the file into buffer
      myFile.read(buffer, sizeof(buffer));

      // Prepare samples
      int volume = 1024;
      Audio.prepare(buffer, S, volume);
      // Feed samples to audio
      Audio.write(buffer, S);

      // Every 100 block print a '.'
      count++;
      if (count == 100) {
        Serial.print(".");
        count = 0;
      }
    }
    myFile.close();


    Serial.println("End of line.");
    return;

while (true) ;


    //access denied
  } else {
    if (count < maxnum)
      Serial.print("Access Denied");
    password.reset();
    digitalWrite(9, HIGH);
    delay(300);
    digitalWrite(9, LOW);

  }

  if (count == 0)
  {
    digitalWrite(14, HIGH);
    digitalWrite(10, HIGH);
    delay(1000);
    digitalWrite(14, LOW);
    digitalWrite(10, LOW);
    count++;
    return;
  }

  if (count == 1)
  {
    digitalWrite(12, HIGH);
    digitalWrite(10, HIGH);
    delay(1000);
    digitalWrite(12, LOW);
    digitalWrite(10, LOW);
    count++;
    return;
  }

  if (count == 2)
  {
    digitalWrite(13, HIGH);
    digitalWrite(10, HIGH);
    delay(1000);
    digitalWrite(13, LOW);
    digitalWrite(10, LOW);
    count = 0;
    return;
  }
}

3 years i have been trying to get this to work… i bought the DUE as from what i have read, it is able to “play audio at a good quality”.

sigh…

thanks.

Try removing this bit of code

      // Every 100 block print a '.'
      count++;
      if (count == 100) {
        Serial.print(".");
        count = 0;
      }

Also be sure that "The Audio file to store on the SD card must be in the .wav format with 44100 Hz, 16-bit stereo quality."

Also, did you ever get the audio functionality working before you started implementing everything else or did you just copy paste the example code into a project in the making? I'm telling you from experience, test 1 functionality at a time, make sure it works, then implement it, make sure it works again, move on.