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
#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)
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.
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.
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.
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.