Pages: [1]   Go Down
Author Topic: "expected unqualified-id before numeric constant"  (Read 6998 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey everyone, ive tried searching, but havent found anything helpful

basically i just got my arduino yesterday, and ive done some simple LED pattern stuff. i tried to do the project in the "getting started with arduino book" through MAKE that was where you press a button, and the LED lights up.

i typed up the code myself, and there are no other problems with it. i had typed out the code so that if i  pressed the button, it did a certain pattern; but i removed that and made it just turn on like the project in the book (over complicating it was what i predicted my problem to
be)

still, it gives me a message that says "error- expected unqualified-id before numeric constant" and it highlights my line that is

Code:
#define BUTTON 4

i have no clue what to do, im just new to this, go easy..

heres my code. (the extra LEDs were used in the more complicated version, but this exact code will not work)

Code:
#define LED 13
#define LED1 12
#define LED2 11
#define LED3 10
#define LED4 9
#define LED5 8
#define LED6 7
#define LED7 6
#define BUTTON 4

int val = 0



void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);
  pinMode(LED7, OUTPUT);
  pinMode(BUTTON, INPUT);
}

void loop(){
  val = digitalRead(BUTTON);

  if (val == HIGH) {
  digitalWrite(LED, HIGH);
  } else {
  digitalWrite(LED, LOW);
  }
}

thanks
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

gotta love my idiocy, i found the problem, i missed the ";" after the "0" in the int line.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2883
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just one thing:
Code:
 val = digitalRead(BUTTON);

 if (val == HIGH) {
  digitalWrite(LED, HIGH);
  } else {
  digitalWrite(LED, LOW);
  }
}  

If "val" is not "==HIGH", it is "==LOW"
hence:
Code:
val = digitalRead(BUTTON);
digitalWrite(LED, val);
smiley-wink
Logged

Per Arduino ad Astra

0
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3420
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And if val is not needed elsewhere it can be removed completely smiley-wink

Code:
 digitalWrite(LED, digitalRead(BUTTON));
Logged

Check out my experiments http://blog.blinkenlight.net

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46059
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hard to de-bounce the button that way, if that's important.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry guys im confused, can you dumb that down for me?

apparently this was supposed to let the button turn it on and off, but it only turns it on, and to turn it off i have to reset the board. any help?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16514
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but it only turns it on, and to turn it off i have to reset the board. any help?

Sounds like a wiring problem with your switch, having a "floating input" when the switch is released. Search around here for pull-ups, pull-downs, and enabling pin software pull-ups. Show us how your switch is wired to the input pin.

Lefty

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46059
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code, as you wrote it, will turn the LED on when the button is pushed, and turn it off when the button is not pushed.

This assumes, of course, that you are using the standard momentary contact pushbutton switch, and that the switch is wired correctly.

Groove's comment was about the fact that the digitalRead function returns either HIGH or LOW, which are the same values that digitalWrite expects as input arguments. So, it is not necessary to test whether the value is HIGH or LOW, if all you are going to do is then pass the value to digitalWrite.

Udo was pointing out that it isn't even necessary to store the value from digitalRead. The function call itself can be use in place of the variable that is normally passed to digitalWrite.

My comment was that switches bounce, and debouncing is sometimes required. Without capturing the output from digitalRead, and evaluating it, you can not do the debouncing.

In your simple case, that is not necessary.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

im sorry, im completely lost, i guess im trying to move too quickly..
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16514
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i guess im trying to move too quickly..

Possibly so. The Arduino does not come with a user pushbutton (not counting the reset switch, which can only reset the chip), so how did you wire up your switch? Did you use an example posted somewhere? Lets get the physical switch wiring correct first and then deal with any remaining software issues.

Lefty
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i got it to work now, sorry to waste space on the forum.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46059
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're not the 1st person to have these kind of problems, and won't be the last. The information exchanged when a newbie has problems is useful for other newbies having the same problems.

It helps those of us that have been programming for a while remember that what comes easily (now) to us is as a result of years of practice, and serves as a reminder that the answers we give need to be in easy to understand terms.

So, don't consider your posting as a waste of space on the forum.

What did you need to do to "get it working"?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i typed in the wrong code, i typed in a code for a different project than the one i was wanting.

im having a problem with a much more complex project, that as far as i know im doing everything right except im confused about the wiring of a button.

should i post that here or start a new thread?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46059
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Start a new thread, with appropriate title.
Logged

Pages: [1]   Go Up
Jump to: