Wave shield has delay when playing sounds in a row...

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
keeleon
 
Posts: 32
Joined: Sun Jul 17, 2011 6:39 pm

Wave shield has delay when playing sounds in a row...

Post by keeleon »

Hi, I am new to Arduino, so please bear with me. I have a wave shield that is assembled, and seems to be working correctly, however, it will occasionally not play a sound after a button press. I am using the 6 button sample code, and have my wavs converted properly. I have soldered wires to the 6 Analog inputs, and one to ground. When I pres the button on the breadboard, or connect the wire to ground, I will get one of the sounds, however, it only seems to work once. Also, if I twist the 2 wires togther, it will play the sound, then like a 9 second pause, and then it MAY play the sound again. Is there some kind of delay built into the code, I am unaware of? Would it be possible or safe to lower it? I would like to be able to play sounds one after another as soon as the previous wav has played by pressing the appropriate button.

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Wave shield has delay when playing sounds in a row...

Post by adafruit_support_bill »

The example code is fairly simple, and only checks for button presses between playing sound-files. If you press the button before the sound finishes playing, it might not catch the button press. To catch button presses at any time, you might want to read-up on interrupts. In the case of the 6-button example, you would need to use 'pin-change' interrupts to handle the 6 switches.
Also, if I twist the 2 wires togther, it will play the sound, then like a 9 second pause, and then it MAY play the sound again.
This is likely due to a combination of things: First, the check_switches() code needs to see a HIGH to LOW transition for a button press. Twisting the wires together will keep the input low. However, breadboard connections sometimes get a little loose which might cause the occasional LOW-HIGH-LOW transition and trigger the sound.

keeleon
 
Posts: 32
Joined: Sun Jul 17, 2011 6:39 pm

Re: Wave shield has delay when playing sounds in a row...

Post by keeleon »

Thanks for the reply
If you press the button before the sound finishes playing, it might not catch the button press.
I figured that much, but this happens even long after the sound has finished playing, and I double checked my wavs to make sure there wasn't trailing silence. I connect the wires, it plays a sound, I disconnect them, and even like 5 seconds after the sound finished, it won't always play again. It also won't play one of the other sounds after this either, even if I switch to a different wire.
This is likely due to a combination of things: First, the check_switches() code needs to see a HIGH to LOW transition for a button press. Twisting the wires together will keep the input low. However, breadboard connections sometimes get a little loose which might cause the occasional LOW-HIGH-LOW transition and trigger the sound.
I thought that the code just compared the state of the wire to a set known "HIGH", and then when it sees it shorted to ground it triggers that part of the code. And then it resets itself again, or is it just constantly checking, and comparing itself to a previous known state? Is there a reason it's checking for a connection to ground, and not to 5v? It seems to me the 2 options are "ground" and "open", vs. "open and voltage" in those 2 scenarios, and it would be a lot more obvious to the board when it had voltage on the line, then when it had ground. Does that make sense?

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Wave shield has delay when playing sounds in a row...

Post by adafruit_support_bill »

I thought that the code just compared the state of the wire to a set known "HIGH",
In the code, you can see that it is also saving and checking the 'previous' state.

Code: Select all

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);
}
Is there a reason it's checking for a connection to ground, and not to 5v?
It may seem counter-intuitive, but it is easier to wire things up if you use inverted logic. The processor has built-in pullup resistors which eliminates the need for external resistors. The pullups are enabled in this section of code:

Code: Select all

  // 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);

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

Return to “Arduino Shields from Adafruit”