odd error i cant figure out

so if i go

void output_angles()
{
  if (output_format == OUTPUT__FORMAT_BINARY)
  {
    float ypr[3];  
    ypr[0] = TO_DEG(yaw);
    ypr[1] = TO_DEG(pitch);
    ypr[2] = TO_DEG(roll);
    Serial.write((byte*) ypr, 12);  // No new-line
  }
  else if (output_format == OUTPUT__FORMAT_TEXT)
  {
    Serial.print("#YPR=");
    Serial.print(TO_DEG(yaw)); Serial.print(",");
    Serial.print(TO_DEG(pitch)); Serial.print(",");
    Serial.print(TO_DEG(roll)); Serial.println();
  }
}

i get

rov2.ino: In function 'void setup()':
rov2:866: error: a function-definition is not allowed here before '{' token
rov2:1286: error: expected `}' at end of input

but if i go like this i get the obvious of

void output_angles()

  if (output_format == OUTPUT__FORMAT_BINARY)
  {
    float ypr[3];  
    ypr[0] = TO_DEG(yaw);
    ypr[1] = TO_DEG(pitch);
    ypr[2] = TO_DEG(roll);
    Serial.write((byte*) ypr, 12);  // No new-line
  }
  else if (output_format == OUTPUT__FORMAT_TEXT)
  {
    Serial.print("#YPR=");
    Serial.print(TO_DEG(yaw)); Serial.print(",");
    Serial.print(TO_DEG(pitch)); Serial.print(",");
    Serial.print(TO_DEG(roll)); Serial.println();
  }
rov2.ino: In function 'void setup()':
rov2:867: error: expected initializer before 'if'
rov2:875: error: 'else' without a previous 'if'
rov2:885: error: a function-definition is not allowed here before '{' token
rov2:1286: error: expected `}' at end of input

so how do i fix???

Post your code.

This

rov2.ino: In function 'void setup()':

tells you the answer. Layout your code !

Mark

ok im obviously missing something here and ive got no idea what as for as i can tell that is the right lay out for that code as ive got no errors else were that ive used the same lay out for an if statement... and the code is way to long to post on the forums....

You can attach the code file to your post.

But I will guess that you have a missing, misplaced, or extra curly brace in your code.

{
// or
}

and the code is way to long to post on the forums....

OK, good luck.

Or, you could attach your code.

(You'll kick yourself when you see the problem)

(You'll kick yourself when you see the problem)

We'll be happy to help, if you can't see the problem. Kick you, that is. 8)

Hi, have you done a "TOOLS" then "Auto Format" tags at the top of the IDE.
I have found that it will apart from align your code indents, it will also check for correct { and }.

Tom..... :slight_smile:

TomGeorge:
Hi, have you done a "TOOLS" then "Auto Format" tags at the top of the IDE.
I have found that it will apart from align your code indents, it will also check for correct { and }.

Tom..... :slight_smile:

What IDE, in 1.5.6 I can't get any errors about missing '{' or '}'.

A worst case scenario even works: "void setup(){{{{{{{{void loop(){int a;" will happily auto format to:
"void setup() { {{{{{{{ void loop() { int a;"

Not even a new line gets inserted. Maybe some features of Auto format were dropped after 1.0.5

Hi, IDE 1.5 tells me that your example has tooo many left {.
IDE 1.5.5 does what 1.5.6 does, no errors.
A feature that will be missed, so if I do my sketch in 1.5.6, I just reload it into 1.5 and do a format.

Tom.... :slight_smile:

so the kicker is it was all due to the lack of a semicolon in the

 if (output_format == OUTPUT__FORMAT_BINARY)

so now its working properly....
i feel like such a noob but thats the fun of learning

which is line 866 in the original code ?

It tells you those line numbers for a reason ! That is where you start looking.

c_batchelar:
so the kicker is it was all due to the lack of a semicolon in the

 if (output_format == OUTPUT__FORMAT_BINARY)

so now its working properly....
i feel like such a noob but thats the fun of learning

Can you please post your working program because it seems to me that a missing semi-colon in that line was probably not the cause of the problem.

void output_angles()
{
  if (output_format == OUTPUT__FORMAT_BINARY);
  {
    float ypr[3];  
    ypr[0] = TO_DEG(yaw);
    ypr[1] = TO_DEG(pitch);
    ypr[2] = TO_DEG(roll);
    Serial.write((byte*) ypr, 12);  // No new-line
  }
  else if (output_format == OUTPUT__FORMAT_TEXT);
  {
    Serial.print("#YPR=");
    Serial.print(TO_DEG(yaw)); Serial.print(",");
    Serial.print(TO_DEG(pitch)); Serial.print(",");
    Serial.print(TO_DEG(roll)); Serial.println();
  }
}

worked after that tho by this point i had used different code

  if (output_format == OUTPUT__FORMAT_BINARY);

I had a suspicion that is what you meant. It is wrong, as is

  else if (output_format == OUTPUT__FORMAT_TEXT);

Look at http://arduino.cc/en/Reference/If carefully. Do you see any semi-colons at the end of the lines except where the test is immediately followed by the one line of code to be executed if the test is true ?

Including the semi-colon effectively stops the test from happening and causes the following code block to be always executed.

ok so my computer is glitching then as ive got the sketch running at the moment....

Nobody said it wouldn't run with the semicolon, but the sketch won't do what you think it should be doing.

ok so thats going to mess with my head... luck im only still playing with that sketch to get a better idea of what im doing...