} Error with code

Hi there, am having an issue with a code that was working before.( Is attached),and I have a new modified version,(is attached as well) and am getting this error…

“NoLimits2RCS_DD_demo.ino: In function ‘void loop()’:
NoLimits2RCS_DD_demo:240: error: expected }' at end of input NoLimits2RCS_DD_demo:240: error: expected }’ at end of input”

I have scanned the script multiple times and I cannot find the culprite that is causing the error.
Any help would be appreciated!
Thanks!

Original Version.ino (8.67 KB)

Modified Version.ino (7.77 KB)

What is the target device?

TTD03:
Hi there, am having an issue with a code that was working before.( Is attached),and I have a new modified version,(is attached as well) and am getting this error…

“NoLimits2RCS_DD_demo.ino: In function ‘void loop()’:
NoLimits2RCS_DD_demo:240: error: expected }' at end of input NoLimits2RCS_DD_demo:240: error: expected }’ at end of input”

I have scanned the script multiple times and I cannot find the culprite that is causing the error.
Any help would be appreciated!
Thanks!

Like the Arduino?
It’s an Arduino Leonardo connected on COM 3.

If you put each { on a new line, and properly indented the code in between the { and it's matching }, you'd see the problem immediately.

Has this anything to do with your other Thread ?

...R

^^ I'm sorry to say I am not a very experienced coder, my friend wrote the script and I've been modifying the script ever since and it has been going alright. But in an instance like this, where my ability is not sufficient enough, I cannot figure it out. If you have found the problem, please share. Thank you.

^ Nope Robin, that issue got solved, completely different issue but same basic code.

When I started coding, I used this format. The opening and closing brackets are indented the same.

if (RestraintHX != RestraintPOS) 
{  //If restraint button has moved...
  delay (100); //Delay 100ms
  if (RestraintPOS == LOW) 
  { //If restraint button in close position...
    RestraintHX = RestraintPOS;
  } //Save new button value
  else 
  { //If restraint button in open position...
    RestraintHX = RestraintPOS;
  } //Save new button value
}

When I started coding, I used this format. The opening and closing brackets are indented the same.

What format do you use now, and why ?

^^ I see you grabbed that from the original version which worked.
What is there now is this.

if (RestraintHX != RestraintPOS)
{  //If restraint button has moved...
  delay (100); //Delay 100ms
  if (RestraintPOS == LOW){ //If restraint button in close position...
   
    
    RestraintHX = RestraintPOS;} //Save new button value
  else{ //If restraint button in open position...
    
    RestraintHX = RestraintPOS;} //Save new button value
}

Is this the part I messed up and not seeing it? Or is it something else that I missed?

Thanks!

@UKHeliBob: I use this now. But there are “helpers” now that highlight the matching opening or closing bracket if you select one. That was not available when Moses and I were sitting around the burning bush learning C with TurboC v1.0. :wink:

if (RestraintHX != RestraintPOS) {  //If restraint button has moved...
  delay (100); //Delay 100ms
  if (RestraintPOS == LOW)   { //If restraint button in close position...
    RestraintHX = RestraintPOS;
  } //Save new button value
  else { //If restraint button in open position...
    RestraintHX = RestraintPOS;
  } //Save new button value
}

^ Am so confused, I see what you changed, but what was wrong with mine?

What is wrong with yours is you can't see the matching opening and closing brackets, and you are missing at least one.

Here is an example of what I recommend for you:

void function()
{
    if(first if)
    {
        if(embedded if)
        {

        }
        else // this indent matches the embedded if, and so do the following brackets
        {

        }
    }
    else // this indent matches first if and the following brackets do also
    {

    }
} // this is the closing bracket for the function

Note how easy it is to see a missing bracket?

Damn, so easy, end of the code, was missing closing brackets, now the code works, how could I have missed that before :confused:

Edit 1:
I decided to start with my original version again and do the same modifications and be more careful about brackets, sure enough, did my changes, not 1 error. Turns out I had deleted 4-5 brackets while modifying the first time.

Edit 2:

Another question:
If you take a look in the Original Version.ino file and look at this part (Near line 190)
Why are there 3 closing brackets? I understand the 2 inner closing brackets but the last and most outer closing bracket specifically on line 202, I can't figure out what that closing bracket is closing. I tried the highlighting thing where you highlight one bracket and then the other highlights, but it is no where to be found. Any help is appreciated, thanks everyone, you guys rock!

If you take a look in the Original Version.ino file and look at this part (Near line 190)
Why are there 3 closing brackets?

You'll need to figure that out for yourself. Your positioning of open and close curly braces absolutely sucks.

PaulS:

If you take a look in the Original Version.ino file and look at this part (Near line 190)
Why are there 3 closing brackets?

You'll need to figure that out for yourself. Your positioning of open and close curly braces absolutely sucks.

I'll let my friend know :stuck_out_tongue: He wrote it.
I figured it out after all. It was way up high in the code.
Thanks for helping everyone!

Ctrl T is the IDE autoformat tool and If you use it frequently
and you miss a curly brace.. This message will show just above the compiler output window.
Autoformat failed; Too Many 'Right' / 'Left' Curly Braces.
left is the opening one and right is the closing curly brace..

Doc

there are "helpers" now that highlight the matching opening or closing bracket if you select one.

Helpers or not, I find that putting each brace on its own line and indenting the code between them much easier, but at least we have the choice.

@UKHeliBob: I still use that "brace on its own line" format if working with complex code. My web client example has the braces on their own line for ease of reading and checking for mismatched braces.
http://playground.arduino.cc/Code/WebClient