Go Down

Topic: Calling software serial and adafruitSFX libraries from another library (Read 570 times) previous topic - next topic

nonlinearmind

I'm using the adafruit soundboard library, which uses the software serial library to play WAV files. I want to be able to trigger these MP3 files from within another library that I've created, but I'm not sure the best way to do it. I have everything so it compiles without errors, but I'm certain that it's far from correct, and more importantly, doesn't play WAVs. So, I'm wondering what the best approach would be to make this work. Any suggestions would be appreciated.

Here are each of my files:

My main sketch:

Code: [Select]
  #include <myLibrary>
#include <SoftwareSerial.h>
#include "Adafruit_Soundboard.h"

void setup(){

 //Soundboard reset
  digitalWrite(12, LOW);
  pinMode(12, OUTPUT);
  delay(10);
  pinMode(12, INPUT);
  delay(1000);
}


void loop(){

playMySound();

delay(5000);
}



myLibrary.h:

Code: [Select]

#include "Arduino.h"
#include <Adafruit_Soundboard.h>
#include "Vcc.h"
      #include <SoftwareSerial.h>
   
void playMySound();


myLibrary.cpp:
Code: [Select]

#include "Arduino.h"   

#include "myLibrary"

#include <Adafruit_Soundboard.h>
#include <SoftwareSerial.h>
#define SFX_TX 10
#define SFX_RX 11
#define SFX_RST 12
     
SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);

void playMySound(){
       
ss.begin(9600);
   
sfx.playTrack("CALI    WAV");     
       
   }




 Just to illustrate, the following, is a sketch example that calls the software serial and soundboard libraries directly and successfully plays the sound file.

Code: [Select]

#include <SoftwareSerial.h>
#include "Adafruit_Soundboard.h"
#define SFX_TX 10
#define SFX_RX 11
#define SFX_RST 12
     
SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);

void setup(){
   
ss.begin(9600);
 
if (!sfx.reset()) {

    Serial.println("Not found");

    while (1);
  }
}


void loop(){

   sfx.playTrack("CALI    WAV");     

delay(5000);
}







Go Up