A function-definition is not allowed here before '{' token

Your code is a mess. This might be the result of posting it here without code tags though I have my doubts; maybe copy/paste errors.

e.g.

void setup()
{

  pinMode(3, OUTPUT); // sets the digital pin 3 as output for a buzzer pinMode(4, OUTPUT); // sets the digital pin 4 as output for an LED pinMode(5, OUTPUT); // sets the digital pin 5 as output for an LED pinMode(6, OUTPUT); // sets the digital pin 6 as output for an LED pinMode(7, OUTPUT); // sets the digital pin 7 as output for an LED pinMode(8, OUTPUT); // sets the digital pin 8 as output for an LED pinMode(9, OUTPUT); // sets the digital pin 9 as output for an LED pinMode(10, OUTPUT); // sets the digital pin 10 as output for an LED pinMode(11, OUTPUT); // sets the digital pin 11 as output for an LED pinMode(12, OUTPUT); // sets the digital pin 12 as output for an LED pinMode(13, OUTPUT); // sets the digital pin 13 as output for an LED Serial.begin(9600);

}

should have been something like

void setup()
{

  pinMode(3, OUTPUT); // sets the digital pin 3 as output for a buzzer
  pinMode(4, OUTPUT); // sets the digital pin 4 as output for an LED 
  pinMode(5, OUTPUT); // sets the digital pin 5 as output for an LED 
  pinMode(6, OUTPUT); // sets the digital pin 6 as output for an LED 
  pinMode(7, OUTPUT); // sets the digital pin 7 as output for an LED 
  pinMode(8, OUTPUT); // sets the digital pin 8 as output for an LED
  pinMode(9, OUTPUT); // sets the digital pin 9 as output for an LED
  pinMode(10, OUTPUT); // sets the digital pin 10 as output for an LED
  pinMode(11, OUTPUT); // sets the digital pin 11 as output for an LED
  pinMode(12, OUTPUT); // sets the digital pin 12 as output for an LED
  pinMode(13, OUTPUT); // sets the digital pin 13 as output for an LED
  Serial.begin(9600);
}

In the above, it's not a disaster (except for the fact that you only set one pin to output :slight_smile: ).

But for these two lines it results in compiler errors

long microsecondsToInches(long microseconds) { // According to Parallax's datasheet))), there are // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per // second). This gives the distance travelled by the ping, outbound // and return, so we divide by 2 to get the distance of the obstacle. return microseconds / 74 / 2; }

  long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2; }