Playing audio from Adafruit Soundboard using file name

I'm trying to control an adafruit soundboard with my elegoo uno R3. I'm a beginner programer and I'm trying to get the soundboard to play a sound file by name when I press a button. I have confirmed the soundboard works because it works when I run the menu program that I got from the tutorial I followed, but when I try to simplify that and transfer it to my own code something goes wrong. Here is my code:

#include <Adafruit_Soundboard.h>
#include <SoftwareSerial.h>

#define SFX_TX 10
#define SFX_RX 11
#define SFX_RST 12

int pin_a = 8;
int pin_b = 7;
int pin_c = 4;
long randNumber;
long randNumberCheck;
const int buttonPin = 2;

int buttonState = 0;
int lightLoopCount = 0;

#define NUM_SOUNDS 2
char *soundName[NUM_SOUNDS] = {
  "T00     OGG",
  "T00     OGG",
};

SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);

void setup() {
  Serial.begin(115200);
  ss.begin(9600);

  if (!sfx.reset()) {
    Serial.println("Not found");
    while (1);
  }
  
  pinMode(pin_a, OUTPUT);
  pinMode(pin_b, OUTPUT);
  pinMode(pin_c, OUTPUT);
  
  pinMode(buttonPin, INPUT);

  randomSeed(analogRead(0));
}

void loop() {
  analogWrite(pin_a, 0);
  analogWrite(pin_b, 0);
  analogWrite(pin_c, 0);
  
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {

    sfx.playTrack(soundName[1]);
    
    if (!sfx.playTrack(soundName[1])) {
      Serial.print("Failed to play");
    }
      
    lightLoopCount = 0;
    while (lightLoopCount < 10) {
      analogWrite(pin_a, 0);
      analogWrite(pin_b, 0);
      analogWrite(pin_c, 0);
      
      // print a random number from 0 to 299
      randNumber = random(3);
      while (randNumber == randNumberCheck) {
        randNumber = random(3);
      }
      
      if (randNumber == 0) {
        analogWrite(pin_a, 255);
      }
      else if (randNumber == 1) {
        analogWrite(pin_b, 255);
      }
      else {
        analogWrite(pin_c, 255);
      }

      randNumberCheck = randNumber;
  
      delay(300);
      lightLoopCount++;
    }
  }
}

I've tried several different ways to get the board to just play a sound by filename when I press the button. Everything else works when I press the button, I think I'm just having trouble converting the string into a char array that the board can understand. It's saying "Failed to play" when I press the button. Can someone help me convert the string properly?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.