Pages: [1]   Go Down
Author Topic: Problem with error message  (Read 641 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Me and my friend don't know how to fix this error, or why it's accouring.
Our code looks like this:


const int buttonPin = 2;
const int hl = 3;
int buttonState = 0;
void setup() {
pinMode(hl, OUTPUT);

pinMode(buttonPin, INPUT);
}
void loop(){

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(hl, LOW);
}
else {
// turn LED off:
digitalWrite(hl, HIGH);
}
}
{
digitalWrite(hl, HIGH)
delay(1000);
digitalWrite(hl, low)
delay(1000)
}

When we try to verify it, we get the error:
Button:57: error: expected unqualified-id before '{' token

Please tell us how to fix the problem!!
Logged

France
Offline Offline
God Member
*****
Karma: 29
Posts: 898
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello and welcome smiley

You have few problems on the last lines:

- First you forgot some ';'

- Then if you check the count of '{' and '}' (and if you indented your code correctly) then you will see the last lines are outside of void loop().


Here is your code, exactly the same but correctly indented:
Code:
const int buttonPin = 2;
const int hl = 3;
int buttonState = 0;

void setup()
{
  pinMode(hl, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
  {
    // turn LED on:
    digitalWrite(hl, LOW);
  }
  else
  {
    // turn LED off:
    digitalWrite(hl, HIGH);
  }
}

{
  digitalWrite(hl, HIGH)
  delay(1000);
  digitalWrite(hl, low)
  delay(1000)
}

See the problem(s) ??
« Last Edit: December 13, 2012, 09:52:43 am by guix » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, thanks for the help, we tried to look at it again, but the error is still not fixed, maybe I don't really get what the error is. It comes with the same error when we try to put the '{' other places.

Please help.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Me and my friend don't know how to fix this error, or why it's accouring (we have very little experience with programming).
Our code looks like this:


const int buttonPin = 2;
const int hl = 3;
int buttonState = 0;
void setup() {
pinMode(hl, OUTPUT);

pinMode(buttonPin, INPUT);
}
void loop(){

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(hl, LOW);
}
else {
// turn LED off:
digitalWrite(hl, HIGH);
}
}
{
digitalWrite(hl, HIGH);
delay(1000);
digitalWrite(hl, LOW);
delay(1000);
}

When we try to verify it, we get the error:
Button:57: error: expected unqualified-id before '{' token

Please tell us how to fix the problem!!
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31472
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You must have an equal number of braces both { and }.

The braces must enclose blocks of code.
The braces in that code are all over the place.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31472
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I imagine that this is what you want, but I am not sure.
Code:
const int buttonPin = 2;
const int hl = 3;
int buttonState = 0;
void setup() {
pinMode(hl, OUTPUT);

pinMode(buttonPin, INPUT);
}
void loop(){

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(hl, LOW);
}
else {
// turn LED off:
digitalWrite(hl, HIGH);
}

digitalWrite(hl, HIGH);
delay(1000);
digitalWrite(hl, LOW);
delay(1000);
}
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First, if you post please use the # button to tag code correctly

Give this a try, I removed a { and added an extra delay(200) , .. (code not tested)
Code:
const int buttonPin = 2;
const int hl = 3;
int buttonState = 0;

void setup()
{
  pinMode(hl, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
  {
    digitalWrite(hl, LOW);
  }
  else
  {
    digitalWrite(hl, HIGH);
  }
  delay(200);  // extra

  digitalWrite(hl, HIGH);
  delay(1000);

  digitalWrite(hl, LOW);
  delay(1000);
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 89
Posts: 3487
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Problem 1 - all the statements should end with a semi-colon like this
Code:
    digitalWrite(hl, HIGH);
Are there any lines in your sketch that don't ?

Problem 2 - when, if ever, is this code going to be executed ?

Code:
{
  digitalWrite(hl, HIGH)
  delay(1000);
  digitalWrite(hl, low)
  delay(1000)
}
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First, if you post please use the # button to tag code correctly

Give this a try, I removed a { and added an extra delay(200) , .. (code not tested)
Code:
const int buttonPin = 2;
const int hl = 3;
int buttonState = 0;

void setup()
{
  pinMode(hl, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
  {
    digitalWrite(hl, LOW);
  }
  else
  {
    digitalWrite(hl, HIGH);
  }
  delay(200);  // extra

  digitalWrite(hl, HIGH);
  delay(1000);

  digitalWrite(hl, LOW);
  delay(1000);
}

Hi, it worked, thanks, but why did you make an extra delay, and why did it work???
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please don't cross post. Threads merged.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Hi, it worked, thanks, but why did you make an extra delay, and why did it work???
That is your homework:)
Follow the code by hand, read it carefully line by line.
Be the Arduino !
and do what the code says and you will understand.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Follow the code by hand, read it carefully line by line.
Be the Arduino !
and do what the code says and you will understand.

Well, ok, thank you! smiley
Logged

Pages: [1]   Go Up
Jump to: