Trying to troubleshoot compiling errors.

I had 2 different sketches that works . I'm trying to combine them in one. As I understand if I copy paste all the declared values to proper section , void setup and void loop to the right place it should work.

I get daphc.pde:128:1: error: expected unqualified-id before '{' token

I don't understand what it asks me to change.

First sketch :

int redPin = 9; 
int greenPin = 10; 
int bluePin = 11; 
byte com = 0; //reply from voice recognition

void setup()
{
Serial.begin(9600);

pinMode(redPin, OUTPUT); 
pinMode(greenPin, OUTPUT); 
pinMode(bluePin, OUTPUT); 
delay(2000);
Serial.write(0xAA);
Serial.write(0x37);
delay(1000);
Serial.write(0xAA);
Serial.write(0x21);
}

void loop()
{
while(Serial.available())
{
com = Serial.read();
switch(com)
{
case 0x11:
digitalWrite(redPin, HIGH);
break;

case 0x12:
digitalWrite(greenPin, HIGH);
break;

case 0x13:
digitalWrite(bluePin, HIGH);
break;

case 0x14:
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
break;

case 0x15:
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
break;
    }
  }
}

Second sketch :

/*
 * 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 redPin = 9; 
int greenPin = 10; 
int bluePin = 11; 
byte com = 0; //reply from voice recognition




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

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

{
  root.rewind();
  play(root);
}

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

Sketch with the error (combined by me):

/*
 * 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 redPin = 9; 
int greenPin = 10; 
int bluePin = 11; 
byte com = 0; //reply from voice recognition




/*
 * 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
  
pinMode(redPin, OUTPUT); 
pinMode(greenPin, OUTPUT); 
pinMode(bluePin, OUTPUT); 
delay(2000);
Serial.write(0xAA);
Serial.write(0x37);
delay(1000);
Serial.write(0xAA);
Serial.write(0x21);


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

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


{
while(Serial.available())
{
com = Serial.read();
switch(com)
{
case 0x11:
digitalWrite(redPin, HIGH);
break;

case 0x12:
digitalWrite(greenPin, HIGH);
break;

case 0x13:
digitalWrite(bluePin, HIGH);
break;

case 0x14:
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
break;

case 0x15:
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
break;
    }
  }
}


{
  root.rewind();
  play(root);
}

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

use alt T and look how the code lines up

the error says line 128 (you can turn on line numbers or bottom left it shows the line the cursor is on)

}
}//you closed the main loop here

{//whats this meant to belong to (line 128)
root.rewind();
play(root);
}

gpop1:
use alt T and look how the code lines up

the error says line 128 (you can turn on line numbers or bottom left it shows the line the cursor is on)

}
}//you closed the main loop here

{//whats this meant to belong to (line 128)
root.rewind();
play(root);
}

Thanks for your reply. When I push alt t it doesn't do anything just print the letter "t" . I figured that if you put the cursor somewhere it shows you what line it is so I can find the right line.

}
}//"you closed the main loop here" so as I understand I have to remove this bracket (to open the loop) and add closing bracket in the end of void loop?

{//"whats this meant to belong to (line 128)"
root.rewind();
play(root);
}

I tried that and it gives me bunch of errors like:

daphc.pde: In function 'void setup()':
daphc.pde:28:37: error: 'error_P' was not declared in this scope
daphc.pde:56:5: note: in expansion of macro 'error'
daphc.pde:28:37: error: 'error_P' was not declared in this scope
daphc.pde:69:5: note: in expansion of macro 'error'
daphc.pde:28:37: error: 'error_P' was not declared in this scope
daphc.pde:80:5: note: in expansion of macro 'error'
daphc.pde: In function 'void loop()':
daphc.pde:137:31: error: a function-definition is not allowed here before '{' token
daphc.pde:207:1: error: expected '}' at end of input
Error compiling.

Can you please show the corrected code.

Code

/*
 * 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 redPin = 9; 
int greenPin = 10; 
int bluePin = 11; 
byte com = 0; //reply from voice recognition




/*
 * 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
  
pinMode(redPin, OUTPUT); 
pinMode(greenPin, OUTPUT); 
pinMode(bluePin, OUTPUT); 
delay(2000);
Serial.write(0xAA);
Serial.write(0x37);
delay(1000);
Serial.write(0xAA);
Serial.write(0x21);


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

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


{
while(Serial.available())
{
com = Serial.read();
switch(com)
{
case 0x11:
digitalWrite(redPin, HIGH);
break;

case 0x12:
digitalWrite(greenPin, HIGH);
break;

case 0x13:
digitalWrite(bluePin, HIGH);
break;

case 0x14:
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
break;

case 0x15:
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
break;
    }
  }



{
  root.rewind();
  play(root);
}

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

When I push alt t it doesn't do anything just print the letter "t"

That's because, on Windows, the shortcut for the Tools + Auto Format menu item is Ctrl T.

PaulS:
That's because, on Windows, the shortcut for the Tools + Auto Format menu item is Ctrl T.

ops my bad. Got so use to doing it with out thinking I never looked to see what the key was called

Built obstacle avoiding robot using arduino uno and arduino r3motor shield. Wiring is correct but will not upload code. It just says error compiling code. I'm cutting and pasting pre written code from arduino but still no luck. Is there anyone who can inform me. Maybe send me a step by step on the subject. Any help would be great. Thanks.

but will not upload code.

What code?

It just says error compiling code.

Your robot does?

I'm cutting and pasting pre written code from arduino but still no luck.

Luck comes into play when buying lottery tickets, not when writing code.

Is there anyone who can inform me.

I wonder, when you hijack an unrelated thread, include no code, no wiring diagram, and no error messages.

bazarishe:
Thanks for your reply. When I push alt t it doesn't do anything just print the letter "t" . I figured that if you put the cursor somewhere it shows you what line it is so I can find the right line.

}
}//"you closed the main loop here" so as I understand I have to remove this bracket (to open the loop) and add closing bracket in the end of void loop?

{//"whats this meant to belong to (line 128)"
root.rewind();
play(root);
}

I tried that and it gives me bunch of errors like:

daphc.pde: In function 'void setup()':
daphc.pde:28:37: error: 'error_P' was not declared in this scope
daphc.pde:56:5: note: in expansion of macro 'error'
daphc.pde:28:37: error: 'error_P' was not declared in this scope
daphc.pde:69:5: note: in expansion of macro 'error'
daphc.pde:28:37: error: 'error_P' was not declared in this scope
daphc.pde:80:5: note: in expansion of macro 'error'
daphc.pde: In function 'void loop()':
daphc.pde:137:31: error: a function-definition is not allowed here before '{' token
daphc.pde:207:1: error: expected '}' at end of input
Error compiling.

Can you please show the corrected code.

Code

/*
  • 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 redPin = 9;
int greenPin = 10;
int bluePin = 11;
byte com = 0; //reply from voice recognition

/*

  • 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
 
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
delay(2000);
Serial.write(0xAA);
Serial.write(0x37);
delay(1000);
Serial.write(0xAA);
Serial.write(0x21);

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  :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.
  root.ls(LS_R | LS_FLAG_FRAGMENTED);
}

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

{
while(Serial.available())
{
com = Serial.read();
switch(com)
{
case 0x11:
digitalWrite(redPin, HIGH);
break;

case 0x12:
digitalWrite(greenPin, HIGH);
break;

case 0x13:
digitalWrite(bluePin, HIGH);
break;

case 0x14:
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, HIGH);
break;

case 0x15:
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
break;
    }
  }

{
  root.rewind();
  play(root);
}

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

Anyone ?

You don't have a closing angle brack for loop(); at least not soon enough. See the annotations in red...

//////////////////////////////////// LOOP

void loop()
// Start of loop function; ok
  while (Serial.available())
  {  // Start of while
    com = Serial.read();
    switch (com)
    { // Start of switch
      case 0x11:
        digitalWrite(redPin, HIGH);
        break;
      : //... blah, blah
    }  // End of Switch
  }  // End of While

// I'm not sure what you're trying to do here, but it's
     //   not actually illegal...
  It creates a "code block"
    root.rewind();
    play(root);
  }  // end of code block..

// About here SHOULD be another closing brace, to end the loop() function.
// But instead you go on to define additional functions inside loop()
// This isn't technically illegal either (I think?), but the functions would only
// have limited "scope" and be visible inside of loop(), instead of "everywhere."

  /////////////////////////////////// HELPERS
  /*
   * print error message and halt
   */
  void error_P(const char *str) {
    PgmPrint("Error: ");
    SerialPrint_P(str);
    sdErrorCheck();
    while (1);
  }