Expected unqualified-id '{' error

Recently, I have been working on this simple code. I keep getting the error message expected unqualified-id '{' error on line 2 of the code on the website codebender, if you're familiar with the website. Here is the code:

{
if(val == 1);
digitalWrite(pin, HIGH);
serial.print1n("LED is on");
}

{
if(val == 2);
digitalWrite(pin, LOW);
serial.print1n("LED is off");
}

Anyone out there who could help, that would be great. FYI, I'm only eleven, and I'm not the best at handling the error messages. Thanks! :smiley:

You're writing those statements wrong. I'd suggest a tutorial on C+ syntax. Check google, there are thousands for free.

A semicolon at the end of an if statement means "Do Nothing"

The braces allow you to put multiple statements into a block after an if statement, but the braces come AFTER the if.

It should look like this instead:

if(val == 1)
{
     digitalWrite(pin, HIGH);
     serial.print1n("LED is on");
}

Thanks for the recommendation! Now, it says expected unqualified-id for if(val == 1) and if(val == 2). I'm not sure what to do.

Post your whole code. Maybe there is an error elsewhere.

if(val == 1)
{
digitalWrite(pin, HIGH);
serial.print1n("LED is on");
}

if(val == 2)
{
digitalWrite(pin, LOW);
serial.print1n("LED is off");
}

//This is the code with the error.

We want to see ALL of the code. Snippets don't help.

Surrounding the code with code tags (the button that looks like a scroll with brackets) would really help too.

And post the actual error code. Your paraphrasing is not something that the compiler would actually say. The specific text of the message can be important.

The code I've used is RedBearLab's code that I have edited for my project. The code is too long to post, but the original code by itself compiled successfully on codebender and currently works on my arduino. After adding the snippet, the website codebender started giving me error messages. They follow exactly as this:

error: expected unqualified-id
if(val == 1)

error: expected unqualified-id
if(val == 2)

To see the exact code, go to codebender and search BLEControllerSketch-copy-copy-copy-copy- copy-copy. Then click the projects tab and click the second one down from the top project, the one I told you guys to search. That will have the whole code, if you want to verify/compile it and you will see what I mean. Thanks guys!

 serial.print1n("LED is off");

The instance is Serial, not serial!

There is no reason why this code could not have been posted here with code tags.

However, I went to the codebender web site (which is actually https://codebender.cc) and looked at the code.

There are at least two problems:

  1. The code is not inside a function.
  2. Nowhere is val defined or given a value.

val is NOT the same as value, value8, value_lo, or value_hi. value may have its own problems anyway.

So how can I fix this? Should I put it in a loop and define val or what?

Or what else have you tried?...

Doc

You can always Attach your code to a Reply here.

Hi;

Can you please post a copy of your sketch, using code tags?
Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

If you use REPLY not QUICK REPLY you will find an ATTATCHMENT function to attach your sketch if it is too big for the code tags.

Where are you assigning a value to val?

Tom... :slight_smile:

I'm only eleven, and I'm not the best at handling the error messages.

Post your code - all of it. Post your error message.

How to use this forum

http://snippets-r-us.com/

This is all of the code that I typed on codebender.com that should be attached(I am editing a RedBearLab bluetooth code and the snippet is at the bottom. Here is the exact error message I am getting:

BLEControllerSketch copy copy copy copy copy.ino:470:2: error: expected unqualified-id
if(val == 1)
^
BLEControllerSketch copy copy copy copy copy.ino:477:1: error: expected unqualified-id
if(val == 2)

BLEControllerSketch-copy-copy-copy-copy-copy.zip (7.32 KB)

  ble_do_events();
  buf_len = 0;
} // <--- This is the end of loop()

if (val == 1)
{

When you get over the idea that you can just put code anywhere, life will get better.

I understand your thinking but that doesn't exactly help much.

I understand your thinking but that doesn't exactly help much.

Well, you won't tell us what you are trying to do, so, I guess we're about even.

I am trying to control a led by a serial monitor over bluetooth. I want the arduino to connect over bluetooth to the computer or a phone, and in the code, whether I type 1 or 2, the led will go on or off and then the serial monitor will print that.