Waveshield / Uno and triggering sketch help!Will pay for assistance.

Hi all,
Need help with coding, for an art project. I will gladly pay a little if anyone can walk me thru this, or just write the code itself.

I have the uno, and ladyada waveshield.
I am trying to play random files off the sd card, and have an FSR trigger a separate sound from a different directory.
The sketch where all files play off the sd card works.(so the cards both work)
FSR sensor, that triggers the led also works, but I am having trouble getting the fsr to trigger another sound.
I'm using digital pin input 11.

Need to finish this by June 30, 2012. Thanks!!!

Please, post how you connected things up in a picture or even schematic, and also the current code, thanks.

Hey, thanks for responding…

I’m using the sample code on the waveshield site for playing all random files, and the code to trigger a led with pin 11 trigger: this part works.

I just need to integrate the two parts together:
code from digital input 11, to trigger 3 separate audio files,(instead of just the led) (interrupting the original random file playback)
The problem I’m having is writing the code that triggers the other 3 files to integrate with the other random files playing in the background.
2 codes are below…
I’m sure this is pretty basic, but I’m not getting anywhere…
The code is exactly the same from the ladyada website:
Plays all random files below:

  • 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
int ir = A0;
//int led = 12; // the pin that the LED is attached to
int timer = 143; // The higher the number, the slower the timing.
char ledPins = {11, 12}; // an array of pin numbers to which LEDs are attached
int pinCount = 7; // the number of pins (i.e. the length of the array)
int val = 0;
int thisPin;


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

//////////////////////////////////// SETUP
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps for debugging

putstring_nl("\nWave test!"); // say we woke up!

putstring("Free RAM: "); // This can help with debugging, running out of RAM is bad

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

// 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 :frowning:
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.

//////////////////////////////////// LOOP
void loop() {

/////////////////////////////////// HELPERS

  • print error message and halt
    void error_P(const char str) {
    PgmPrint("Error: ");
  • 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);
  • 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)) {

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: ");
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
if (!(++n % 32))Serial.println();
sdErrorCheck(); // everything OK?
// if (wave.errors)Serial.println(wave.errors); // wave decoding errors

pin 11 activates the led on pin 13…


Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.

The circuit:

  • LED attached from pin 11 to ground

  • pushbutton attached to pin 2 from +5V

  • 10K resistor attached to pin 2 from ground

  • Note: on most Arduinos there is already an LED on the board
    attached to pin 13.

created 2005
by DojoDave http://www.0j0.org
modified 30 Aug 2011
by Tom Igoe

This example code is in the public domain.


// constants won’t change. They’re used here to
// set pin numbers:
const int buttonPin = 11; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
else {
// turn LED off:
digitalWrite(ledPin, LOW);