I got the WAV shield and after some problems....due to some missed solder points...I got it working ! Now...is there some code so that I can use to address specific sound files. So, when a "button" is pressed, such and such file is played and so on ( up to as many sounds as possible...)
Thanks !
Christopher
triggering sounds
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 10
- Joined: Thu May 22, 2008 12:42 pm
cippo65,
Here's my code that plays different sounds when you ground one of the analog input pins (0 - 5).
It uses a modified version of the Arduino example switch debounce code.
"check_switches()" return the values 1 through 6 for pins 0 through 5.
A value of 0 is returned if no pin is grounded.
Pin 0 plays "SOUND1.WAV", pin 1 plays "SOUND2.WAV", etc., up to pin 5 which plays "SOUND6.WAV".
Regards,
Eric
Here's my code that plays different sounds when you ground one of the analog input pins (0 - 5).
It uses a modified version of the Arduino example switch debounce code.
"check_switches()" return the values 1 through 6 for pins 0 through 5.
A value of 0 is returned if no pin is grounded.
Pin 0 plays "SOUND1.WAV", pin 1 plays "SOUND2.WAV", etc., up to pin 5 which plays "SOUND6.WAV".
Code: Select all
#include <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("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");
}
}
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();
}
}
Eric
-
- Posts: 11
- Joined: Wed Jul 02, 2008 5:51 am
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 want it to play a generator 'humm' effect and then when a button is pressed pay another sample that ramps up the generator, and another that slows it back down... as the sound is supposed to be continuous, I dont want it to pause in between sounds..
if that makes sense... )
Also I am reading that this totally fills up the capability of a board, so I could get another arduino to control this one and 'press its buttons' as sound effects are needed I am guessing??
I have never used one of these before, but it looks like I can program them to cointrol the sound and light show on my sculpture I am guessing...
I want it to play a generator 'humm' effect and then when a button is pressed pay another sample that ramps up the generator, and another that slows it back down... as the sound is supposed to be continuous, I dont want it to pause in between sounds..
if that makes sense... )
Also I am reading that this totally fills up the capability of a board, so I could get another arduino to control this one and 'press its buttons' as sound effects are needed I am guessing??
I have never used one of these before, but it looks like I can program them to cointrol the sound and light show on my sculpture I am guessing...
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
i think its quite fast to start not 'instantaneous' tho. i havent measured it...i would guess about 200 millisecrasterblaster 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..
yup you could do that pretty easily. or just send it 'serial' commandsAlso I am reading that this totally fills up the capability of a board, so I could get another arduino to control this one and 'press its buttons' as sound effects are needed I am guessing??
-
- Posts: 10
- Joined: Thu May 22, 2008 12:42 pm
Here's a slightly modified version that will start playing a new sound while another is
still playing, instead of waiting until the currently playing sound finishes.
It certainly seems like the change from one sound to the other is instantaneous.
Regards,
Eric
still playing, instead of waiting until the currently playing sound finishes.
It certainly seems like the change from one sound to the other is instantaneous.
Regards,
Eric
Code: Select all
#include <AF_Wave.h>
#include <avr/pgmspace.h>
#include "util.h"
#include "wave.h"
#define DEBOUNCE 20
#define swPin 14
AF_Wave card;
File f;
Wavefile wave;
void setup() {
byte i;
// set up serial port
Serial.begin(9600);
// set up waveshield pins
for (byte i = 2; i <= 5; ++i) {
pinMode(i, OUTPUT);
}
// enable pull-up resistors on
// switch pins (analog inputs)
for (byte i = swPin; i <= swPin + 5; ++i) {
digitalWrite(i, 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:
playfile("SOUND1.WAV");
break;
case 2:
playfile("SOUND2.WAV");
break;
case 3:
playfile("SOUND3.WAV");
break;
case 4:
playfile("SOUND4.WAV");
break;
case 5:
playfile("SOUND5.WAV");
break;
case 6:
playfile("SOUND6.WAV");
}
}
byte check_switches()
{
static byte previous[6];
static long time[6];
byte reading;
byte pressed;
byte index;
for (index = 0; index < 6; ++index) {
reading = digitalRead(swPin + 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 playfile(char *name) {
// stop any file already playing
if (wave.isplaying) {
wave.stop();
}
// close file if open
if (f) {
card.close_file(f);
}
// play specified file
f = card.open_file(name);
if (f && wave.create(f)) {
wave.play();
}
}
-
- Posts: 2
- Joined: Fri Jul 04, 2008 5:53 am
How can I do this with one button?
Hi,
I'm just trying to get this to work with one button rather than 6 but am struggling.
Basically I have a number of tracks and want to know how to get one button to jump to the next track.
Any thoughts?
Thanks,
Ben
I'm just trying to get this to work with one button rather than 6 but am struggling.
Basically I have a number of tracks and want to know how to get one button to jump to the next track.
Any thoughts?
Thanks,
Ben
-
- Posts: 7
- Joined: Wed Jul 09, 2008 9:32 pm
Thanks for the code above! I got it working and it's so close to what I need, but I have one question. I'm trying to make a sound box for my little girl's first birthday and I would like four buttons to make individual sounds. This works, but after a sound ends, no more buttons can be pressed without reseting the arduino. Is there an easy fix that would allow me to reset the arduino after a file finishes playing or something like that?
Thanks.
Thanks.
-
- Posts: 11
- Joined: Wed Jul 02, 2008 5:51 am
- intellijel
- Posts: 48
- Joined: Mon Aug 15, 2005 6:14 pm
I have tried the code and would not work for me.
My wave shield definitely works (I tried other sketches that just play the audio files on the disk)
and I tried editing the code so it is not waiting for buttons presses, it just plays the first file in a loop.
What I can't get to work is button responses. I measured the analog in pins and the voltage is 5V (so the pullup is working) and when I ground the pins the input goes to 0 but I get no response.
I need to put some debugging points in but I was wondering if anyone else experienced issues. Is this due to the debouncing settings?
thanks,
Danjel
My wave shield definitely works (I tried other sketches that just play the audio files on the disk)
and I tried editing the code so it is not waiting for buttons presses, it just plays the first file in a loop.
What I can't get to work is button responses. I measured the analog in pins and the voltage is 5V (so the pullup is working) and when I ground the pins the input goes to 0 but I get no response.
I need to put some debugging points in but I was wondering if anyone else experienced issues. Is this due to the debouncing settings?
thanks,
Danjel
-
- Posts: 7
- Joined: Wed Jul 09, 2008 9:32 pm
Please be positive and constructive with your questions and comments.