0

Wave Shield confusion
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Wave Shield confusion

by 0hm_Mic_0dd on Thu Dec 06, 2018 2:55 pm

Hi,
I'm on this step of the tutorial for the Wave Shield: https://learn.adafruit.com/adafruit-wav ... c-library#

I'm unsure if the SD card needs to be installed into the shield before initializing or if it should stay mounted to the computer I'm using. It's unclear where it needs to be for this step and the previous step in the tutorial says to add wav files directly onto the card. This is super confusing because I thought initializing the SD card means it will clear all data from the card.
Is this not the case? Can someone please fill me in on the exact next steps? My board is all soldered up and the libraries are installed, I just need help with the step I'm on.
I appreciate any help please and thank you!

0hm_Mic_0dd
 
Posts: 32
Joined: Thu Dec 06, 2018 2:51 pm

Re: Wave Shield confusion

by adafruit_support_carter on Thu Dec 06, 2018 3:04 pm

You will want the SD card in the shield for that part of the guide. What the guide is doing at that point is walking you through the source code and explaining how it works. So in that case "initialize" is referring to the software initialization, not the card itself.

adafruit_support_carter
 
Posts: 7676
Joined: Tue Nov 29, 2016 2:45 pm

Re: Wave Shield confusion

by 0hm_Mic_0dd on Thu Dec 06, 2018 4:31 pm

Thank you! That's really helpful.
And so the wav files should definitely be placed on the card before inserting into the shield?

0hm_Mic_0dd
 
Posts: 32
Joined: Thu Dec 06, 2018 2:51 pm

Re: Wave Shield confusion

by 0hm_Mic_0dd on Thu Dec 06, 2018 4:54 pm

Nevermind that last question, I got it working!!! Now I just need to integrate with an HC-SR04 sensor...

..Who knew playing an audio file could be so complex?

0hm_Mic_0dd
 
Posts: 32
Joined: Thu Dec 06, 2018 2:51 pm

Re: Wave Shield confusion

by 0hm_Mic_0dd on Tue Dec 11, 2018 2:26 pm

Ok I need more help on this. I've been trying to set up for this 6-button example found here: https://learn.adafruit.com/pages/1334/e ... 6/download

But this would be so much easier to start testing if it was just one button rather than 6. There seem to be 2 different versions of this "play6_HC" example on this page (more confusion) and it's unclear why one has so much additional code.

What I'm trying to do is very simple: trigger a sound (or ideally a random choice of several sounds) when an ultrasonic sensor reads an object between 2 distances. I have the sensor working just fine and I tried to cobble together the daphc sample code with my ultrasonic sensor code, but it did not work.

What I have working: the sound I have loaded onto the card is playing in a loop with the daphc code loaded onto the board, so that works, I'm struggling to get functionality with the ultrasonic sensor though.

Please help!

0hm_Mic_0dd
 
Posts: 32
Joined: Thu Dec 06, 2018 2:51 pm

Re: Wave Shield confusion

by adafruit_support_carter on Tue Dec 11, 2018 2:39 pm

You could just reduce the switch statement to a single case for one button. But that code may not be the best to adapt from. You have the sensor working. Try working out the sensor trigger logic using Serial.println()'s. Have it print things like "PLAYING AUDIO". Get the prints to work like you want. Then try replacing the Serial.println()'s with code that actually plays audio.

adafruit_support_carter
 
Posts: 7676
Joined: Tue Nov 29, 2016 2:45 pm

Re: Wave Shield confusion

by 0hm_Mic_0dd on Tue Dec 11, 2018 3:42 pm

I have that working already in this code using an LED as an actuator (see below)
The difficulty I'm having is parsing out which lines of code inside of the play6_hc or daphc code actually play the audio file. So I'm looking to replace the lines found within the loop section, but I tried and failed. Gonna keep hammering away at it....
Code: Select all | TOGGLE FULL SIZE
// ---------------------------------------------------------------------------

#include <NewPing.h>

#define TRIGGER_PIN  11  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     12  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
#define LED 2 // blink test

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.
  pinMode (LED, OUTPUT); //set LED pin to output
  digitalWrite(LED, LOW); //set LED to dark
 
}

void loop() {
  int Distance= sonar.ping_cm();
  delay(50);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  Serial.print("Ping: ");
  Serial.print(Distance); // Send ping, get distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");

  if(Distance < 100){
    digitalWrite(LED, HIGH);
  }
  else{digitalWrite(LED, LOW);}
}
Last edited by adafruit_support_carter on Tue Dec 11, 2018 3:59 pm, edited 1 time in total.
Reason: added [code] tags

0hm_Mic_0dd
 
Posts: 32
Joined: Thu Dec 06, 2018 2:51 pm

Re: Wave Shield confusion

by 0hm_Mic_0dd on Tue Dec 11, 2018 3:46 pm

For reference, here is the code I tried to cobble together from the Ultrasonic sensor code and the daphc code (I put a note where I think things went bad) ::
Code: Select all | TOGGLE FULL SIZE
// ---------------------------------------------------------------------------
// Example NewPing library sketch that does a ping about 20 times per second.
// ---------------------------------------------------------------------------

#include <NewPing.h>

#define TRIGGER_PIN  11  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     12  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
//#define LED 2 // blink test

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
/*
 * This example plays every .WAV file it finds on the SD card in a loop
 */
#include <WaveHC.h>
#include <WaveUtil.h>

SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the volumes root directory
WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

uint8_t dirLevel; // indent level for file/dir names    (for prettyprinting)
dir_t dirBuf;     // buffer for directory reads


/*
 * Define macro to put error messages in flash memory
 */
#define error(msg) error_P(PSTR(msg))

// Function definitions (we define them here, but the code is below)
void play(FatReader &dir);

void setup() {
  Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.
  //pinMode (LED, OUTPUT); //set LED pin to output
  //digitalWrite(LED, LOW); //set LED to dark

putstring_nl("\nWave test!");  // say we woke up!
 
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(FreeRam());

  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!) 
    error("Card init. failed!");  // Something went wrong, lets print out why
  }
 
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {   // we have up to 5 slots to look in
    if (vol.init(card, part))
      break;                           // we found one, lets bail
  }
  if (part == 5) {                     // if we ended up not finding one  :(
    error("No valid FAT partition!");  // Something went wrong, lets print out why
  }
 
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(), DEC);     // FAT16 or FAT32?
 
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    error("Can't open root dir!");      // Something went wrong,
  }
 
  // Whew! We got past the tough parts.
  putstring_nl("Files found (* = fragmented):");

  // Print out all of the files in all the directories.
  root.ls(LS_R | LS_FLAG_FRAGMENTED);
}


void loop() {
  int Distance= sonar.ping_cm();
  delay(500);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  Serial.print("Ping: ");
  Serial.print(Distance); // Send ping, get distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");

  if(Distance < 100){
    //digitalWrite(LED, HIGH); //this line used to test sensor functionality;
    root.rewind(); // ****HERE IS WHERE I THOUGHT THE AUDIO WOULD PLAY****
  play(root);
  }
  else{
    //digitalWrite(LED, LOW);
    }
}

/////////////////////////////////// HELPERS
/*
 * print error message and halt
 */
void error_P(const char *str) {
  PgmPrint("Error: ");
  SerialPrint_P(str);
  sdErrorCheck();
  while(1);
}
/*
 * print error message and halt if SD I/O error, great for debugging!
 */
void sdErrorCheck(void) {
  if (!card.errorCode()) return;
  PgmPrint("\r\nSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  PgmPrint(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}
/*
 * play recursively - possible stack overflow if subdirectories too nested
 */
void play(FatReader &dir) {
  FatReader file;
  while (dir.readDir(dirBuf) > 0) {    // Read every file in the directory one at a time
 
    // Skip it if not a subdirectory and not a .WAV file
    if (!DIR_IS_SUBDIR(dirBuf)
         && strncmp_P((char *)&dirBuf.name[8], PSTR("WAV"), 3)) {
      continue;
    }

    Serial.println();            // clear out a new line
   
    for (uint8_t i = 0; i < dirLevel; i++) {
       Serial.write(' ');       // this is for prettyprinting, put spaces in front
    }
    if (!file.open(vol, dirBuf)) {        // open the file in the directory
      error("file.open failed");          // something went wrong
    }
   
    if (file.isDir()) {                   // check if we opened a new directory
      putstring("Subdir: ");
      printEntryName(dirBuf);
      Serial.println();
      dirLevel += 2;                      // add more spaces
      // play files in subdirectory
      play(file);                         // recursive!
      dirLevel -= 2;   
    }
    else {
      // Aha! we found a file that isnt a directory
      putstring("Playing ");
      printEntryName(dirBuf);              // print it out
      if (!wave.create(file)) {            // Figure out, is it a WAV proper?
        putstring(" Not a valid WAV");     // ok skip it
      } else {
        Serial.println();                  // Hooray it IS a WAV proper!
        wave.play();                       // make some noise!
       
        uint8_t n = 0;
        while (wave.isplaying) {// playing occurs in interrupts, so we print dots in realtime
          putstring(".");
          if (!(++n % 32))Serial.println();
          delay(100);
        }       
        sdErrorCheck();                    // everything OK?
        // if (wave.errors)Serial.println(wave.errors);     // wave decoding errors
      }
    }
  }
}
Last edited by adafruit_support_carter on Tue Dec 11, 2018 3:59 pm, edited 1 time in total.
Reason: added [code] tags

0hm_Mic_0dd
 
Posts: 32
Joined: Thu Dec 06, 2018 2:51 pm

Re: Wave Shield confusion

by adafruit_support_carter on Tue Dec 11, 2018 4:03 pm

It's the call to playComplete here which plays the files depending on which button is pressed.
Code: Select all | TOGGLE FULL SIZE
  switch (check_switches()) {
    case 1:
      playcomplete("SOUND1.WAV");
      break;
    case 2:
      playcomplete("SOUND2.WAV");
      break;
    case 3:
      playcomplete("SOUND3.WAV");
      break;
    case 4:
      playcomplete("SOUND4.WAV");
      break;
    case 5:
      playcomplete("SOUND5.WAV");
      break;
    case 6:
      playcomplete("SOUND6.WAV");
  }

But note that playComplete simply calls playfile:
https://learn.adafruit.com/adafruit-wav ... yfile-14-7
which makes the actual library calls to do the playback.

adafruit_support_carter
 
Posts: 7676
Joined: Tue Nov 29, 2016 2:45 pm

Re: Wave Shield confusion

by 0hm_Mic_0dd on Tue Dec 11, 2018 5:26 pm

I went ahead and hooked up 6 reed switches just to get the play6 code working and am having success playing my own sound files that are loaded onto the card, now the challenge is to somehow replace the on/off switching function with the range triggered function of the ultrasonic sensor.
Will update tomorrow...

Thank you for all your help!!

0hm_Mic_0dd
 
Posts: 32
Joined: Thu Dec 06, 2018 2:51 pm

Re: Wave Shield confusion

by 0hm_Mic_0dd on Wed Dec 12, 2018 1:10 pm

Having difficulty getting the code to work and all sound from the switches stops when I connect the HC-SR04 sensor to ground.
The code compiles and uploads fine, but the serial printout tells me there is a card error. I can try to recreate the card error and screenshot it, but maybe something will stand out in the code?
Code: Select all | TOGGLE FULL SIZE
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"

#include <NewPing.h>


SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

#define DEBOUNCE 100  // button debouncer

#define TRIGGER_PIN  11  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     12  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end;
  extern int  *__brkval;
  int free_memory;
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
  }
  return free_memory;
}

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

void setup() {
  // set up serial port
  Serial.begin(9600);
  putstring_nl("WaveHC with 6 buttons");
 
   putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
 
  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
 
  // pin13 LED
  pinMode(13, OUTPUT);
 
  // enable pull-up resistors on switch pins (analog inputs)
  digitalWrite(14, HIGH);
  digitalWrite(15, HIGH);
  digitalWrite(16, HIGH);
  digitalWrite(17, HIGH);
  digitalWrite(18, HIGH);
  digitalWrite(19, HIGH);
 
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!) 
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
 
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part))
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
 
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
 
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
 
  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
}

void loop() {
  //putstring(".");            // uncomment this to see if the loop isnt running
  switch (check_switches()) {
    case 1:
      playcomplete("FART1.WAV");
      break;
    case 2:
      playcomplete("FART2.WAV");
      break;
    case 3:
      playcomplete("FART3.WAV");
      break;
    case 4:
      playcomplete("FART1.WAV");
      break;
    case 5:
      playcomplete("FART2.WAV");
      break;
    case 6:
      playcomplete("FART3.WAV");
  }

  int Distance= sonar.ping_cm();
  delay(50);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  Serial.print("Ping: ");
  Serial.print(Distance); // Send ping, get distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");

  if(Distance < 100){
    playcomplete("FART3.WAV");
  }
  else{
playcomplete("FART2.WAV");
}
}

byte check_switches()
{
  static byte previous[6];
  static long time[6];
  byte reading;
  byte pressed;
  byte index;
  pressed = 0;

  for (byte index = 0; index < 6; ++index) {
    reading = digitalRead(14 + index);
    if (reading == LOW && previous[index] == HIGH && millis() - time[index] > DEBOUNCE)
    {
      // switch pressed
      time[index] = millis();
      pressed = index + 1;
      break;
    }
    previous[index] = reading;
  }
  // return switch number (1 - 6)
  return (pressed);
}

// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  // do nothing while its playing
  }
  // now its done playing
}

void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
 
  // ok time to play! start playback
  wave.play();
}
Last edited by adafruit_support_carter on Wed Dec 12, 2018 1:39 pm, edited 1 time in total.
Reason: added [code] tags

0hm_Mic_0dd
 
Posts: 32
Joined: Thu Dec 06, 2018 2:51 pm

Re: Wave Shield confusion

by adafruit_support_carter on Wed Dec 12, 2018 1:42 pm

Nothing obvious. Go back to a working example and see if it also shows an SD card issue. If it complains also then it might be hardware related.

adafruit_support_carter
 
Posts: 7676
Joined: Tue Nov 29, 2016 2:45 pm

Re: Wave Shield confusion

by 0hm_Mic_0dd on Wed Dec 12, 2018 4:32 pm

Okay I tried a different Ultrasonic code by Dejan Nedelkovski (one that didn't use an embedded library) and attempted to cobble it together like this (see below) but got an error code 3, error data 0 which reads "No valid FAT partition!"
I'm not understanding why this code works for some switches and not others?

Code: Select all | TOGGLE FULL SIZE
/*
* Ultrasonic Sensor HC-SR04 and Arduino Tutorial
*
* by Dejan Nedelkovski,
* http://www.HowToMechatronics.com
*
*/
// defines pins numbers
const int trigPin = 11;
const int echoPin = 12;
// defines variables
long duration;
int distance;

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"


SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

#define DEBOUNCE 100  // button debouncer

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end;
  extern int  *__brkval;
  int free_memory;
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
  }
  return free_memory;
}

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication

 putstring_nl("WaveHC with 6 buttons");
 
   putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
 
  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
 
  // pin13 LED
  pinMode(13, OUTPUT);

  if (!card.init()) {         //play with 8 MHz spi (default faster!) 
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
 
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part))
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
 
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
 
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
 
  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
}


void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);

  if(distance < 80){
    playcomplete("FART1.WAV");
  }
}

// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  // do nothing while its playing
  }
  // now its done playing
}

void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
 
  // ok time to play! start playback
  wave.play();
}
Last edited by adafruit_support_carter on Thu Dec 13, 2018 1:13 pm, edited 1 time in total.
Reason: added [code] tags

0hm_Mic_0dd
 
Posts: 32
Joined: Thu Dec 06, 2018 2:51 pm

Re: Wave Shield confusion

by 0hm_Mic_0dd on Thu Dec 13, 2018 11:31 am

Getting very lost in code... I think my confusion lies in shifting from a switch...case function that makes use of byte to a function that reads a range of parameters. Wondering if I maybe need to use 2 Arduinos - one just for the HC-SR04 and one just for the Wave Shield and feed the output signals into the reed switches.
Thoughts before i try that?

0hm_Mic_0dd
 
Posts: 32
Joined: Thu Dec 06, 2018 2:51 pm

Re: Wave Shield confusion

by adafruit_support_carter on Thu Dec 13, 2018 1:15 pm

What I'm trying to do is very simple: trigger a sound (or ideally a random choice of several sounds) when an ultrasonic sensor reads an object between 2 distances.

That should be doable on a single board running one program.

adafruit_support_carter
 
Posts: 7676
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.