triggering sounds

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
intellijel
 
Posts: 48
Joined: Mon Aug 15, 2005 6:14 pm

Post by intellijel »

Sure it is exactly the same code posted above. I just reduced the number of case choices and changed the soundfile names:

#i

Code: Select all

nclude <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"

#define DEBOUNCE 100

#define swPin 14

AF_Wave card;
File f;
Wavefile wave;

void setup() {
  // set up serial port
  Serial.begin(9600);

  // set up waveshield pins
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, 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);

  // open memory card
  if (!card.init_card()) {
    putstring_nl("Card init failed!"); return;
  }
  if (!card.open_partition()) {
    putstring_nl("No partition!"); return;
  }
  if (!card.open_filesys()) {
    putstring_nl("Couldn't open filesys"); return;
  }
  if (!card.open_rootdir()) {
    putstring_nl("Couldn't open dir"); return;
  }
}

void loop() {   
  switch (check_switches()) {
    case 1:
      playcomplete("SOUND001.WAV");
      break;
    case 2:
      playcomplete("SOUND002.WAV");
      break;
  }
}

byte check_switches()
{
  static byte previous[6];
  static long time[6];
  byte reading;
  byte pressed;
  byte index;
 
  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);
}

void playcomplete(char *name) {
  playfile(name);
  while (wave.isplaying);
  card.close_file(f);
}

void playfile(char *name) {
  // stop any file already playing
  if (wave.isplaying) {
    wave.stop();
    card.close_file(f);
  }

  f = card.open_file(name);
  if (f && wave.create(f)) {
    wave.play();
  }
} 

Honus
 
Posts: 19
Joined: Mon Jun 18, 2007 11:02 pm

Post by Honus »

I have the exact same problem- I tried the interrupt code exactly as it is originally posted and I'm currently using version 10. All other sketches play just fine. I haven't yet had a chance to mess around with it. Strange.....

User avatar
intellijel
 
Posts: 48
Joined: Mon Aug 15, 2005 6:14 pm

Post by intellijel »

I actually got it working (I think it was a loose connection that I resoldered).

Now I have a bigger problem that some of the digital i/o pins are not working properly. When I use them as outputs I can't seem to set there voltage (e.g. some are stuck high or low permanently like pins 13,12,11...)

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Post by adafruit »

ya, some of those pins are used for talking to the SD card
check the webpage and schematic!

User avatar
intellijel
 
Posts: 48
Joined: Mon Aug 15, 2005 6:14 pm

Post by intellijel »

cool, that was it!

i/o Pins used by the Wave Shield:

13,12,11,10
5,4,3,2

Everything else seems to be free afaik

Losroper
 
Posts: 1
Joined: Fri Sep 05, 2008 8:46 am

Post by Losroper »

ladyada wrote:
rasterblaster wrote:Just thinking of buying one of these to do sound effects for a sculpture, and I was wondering what delay is there when switching between soundeffects..
i think its quite fast to start not 'instantaneous' tho. i havent measured it...i would guess about 200 millisec
Hi ladyada.

I've just buy a nice Audio Wave Shield and I'm too happy using it.

Yes, the delay could be about 200ms ... but when you have a lot of wave files in the SD (150) the system take different delay to play each one (depending on the position in the directory).

Is there any way to index the files for a quick response?

I'm trying to develop an Arduino project to say numbers (for example 12.543 linking three wave files, in this case twelve.wav + fivehundred.wav + fortythree.wav) and I have to include aprox. 125 wave files.

Thank you for your help.

beardy241
 
Posts: 20
Joined: Tue Feb 17, 2009 9:19 pm

Re: triggering sounds

Post by beardy241 »

Hmm. Strange things afoot here.

1)
I'm able to run the code initially posted to this thread by ebs (thank you!) - albeit I have to comment out case:1 because it constantly thinks that button 1 has been pressed. That's a great start.

2)
Trying ebs' second posting (that allows you to change file whilst there is already one playing) just doesn't play. a) I have to comment out button 1 again, but more importantly b) it never plays a whole sound and keeps scanning through all 6 sounds playing a bare snippet of each. Serial Monitor likes to report "All done, no errors" repeatedly.

I'm using IDEv12 (Mac 10.4.11)
I've tried a Diecimila and a Seeeduino board.

I'm puzzled.

Many thanks if you can offer insight here.

Marcel

User avatar
jeffhaas
 
Posts: 22
Joined: Wed Jun 03, 2009 2:12 am

Re: triggering sounds

Post by jeffhaas »

I'm running into a very similar issue.

I'm using a Duemilanove and a WAV Shield that I picked up at the Maker Faire, on IDE 0015 on Windows XP. The sample sketches run fine...playing everything in a loop, PI party, etc. I have added the buffer edit to free up some RAM.

Running the first sketch in this thread will repeat the first wav file over and over. It requires that case 1 is commented out. Then it works, but of course the first pin doesn't respond.

Running the second sketch gives me the same result, you can hear that files are being played continuously. If I comment out case 1, the sketch works and I can trigger each of the wavs for the pins other than pin 1. Also, with the second sketch, I do notice a bit of a "pop" in the ear bud when a sound is interrupted in order to play another one.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: triggering sounds

Post by adafruit »

the pop is due to the fact that you're switching waveforms very quickly. putting a slight "delaymicroseconds" in between may help this. experiment with different delays

User avatar
jeffhaas
 
Posts: 22
Joined: Wed Jun 03, 2009 2:12 am

Re: triggering sounds

Post by jeffhaas »

Thanks, I'll give that a try.

Any idea on why the sketches don't work completely?

User avatar
tugman
 
Posts: 1
Joined: Mon Jun 08, 2009 9:50 pm

Re: triggering sounds

Post by tugman »

If anyone has code that works with 6 buttons with or without delays could you please post it?

User avatar
jeffhaas
 
Posts: 22
Joined: Wed Jun 03, 2009 2:12 am

Re: triggering sounds

Post by jeffhaas »

Ah ha! The problem with the sketches was solved by another user in May. See this thread:

http://forums.ladyada.net/viewtopic.php?f=31&t=10887

I tested this with both sketches earlier in this thread (the one that plays one file at a time, and the one that interrupts a playing file) and it works.

Haven't tried the "delaymicroseconds" bit yet.

langstraad
 
Posts: 3
Joined: Sun Aug 16, 2009 1:43 am

Re: triggering sounds

Post by langstraad »

I'm in the same boat as Danjel using a freshly built Waveshield 1.0. Other sketches play SOUND1.WAV through SOUND6.WAV but the triggers don't work when connecting the analog pins 0-5 to the ground pin. All of the analog pins read 5V when connected to the ground pin.

Any ideas? I've tried both sets of code from Eric.

langstraad
 
Posts: 3
Joined: Sun Aug 16, 2009 1:43 am

Re: triggering sounds

Post by langstraad »

To be clear, I'm not getting the 1st file looping problem: no triggers on pins 0-5 are working (unless I'm missing something obvious about how to ground the pins). I've inspected all of the solder joints. Any troubleshooting suggestions would be most appreciated.

Diecimila 168 (with buffer adjustment) + Waveshield 1.0

langstraad
 
Posts: 3
Joined: Sun Aug 16, 2009 1:43 am

Re: triggering sounds

Post by langstraad »

Hooray! I got it working on pins 1-5.
The problem turned out to be extra filesystem metadata and ._files on the SD card.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”