iussues with toggling the ledValue of a push button code

I'e been spending the past few days trying to figure this out, from attempting to use a boolean flag to the example code i'm about to show.

The code is:

const int buttonPin = 2;
const int ledPin = 13;

int buttonState = LOW;
int ledValue = LOW;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);

}

void loop() {
buttonState = digitalRead(buttonPin);

if(digitalRead(buttonState) == HIGH)
{
ledValue = !ledValue;
digitalWrite(ledPin, ledValue);
delay(500);
}
}

The portion i'm having issues with at the moment is:

" ledValue = !ledValue; "

(with the issue reading "error: 'ledValue' was not declared in this scope.)

According to the line of code, it SHOULD be reading the button status, and if its pushed, change the ledValue (LOW) to its opposite state (HIGH), and rewrite that for the next loop, with a debounce delay of 500 milliseconds so it doesn't do the loop multiple times in one button push. If anyone knows whats up with the code, let me know, and if any further issues come later up or if i can figure it out myself, i'll update the thread ASAP.

-Ocelot

Please lost the exact code you're having problems with (in code tags) and the exact error message you're seeing.

I see no reason why the code you posted won't compile. Is that all of your code? And again, please use code tags.

Also, what version of the IDE are you using, for completeness sake... (the fancy syntax highlighting makes me suspicious, I don't think that's what my code looks like when I copy/paste it into forums)

The following line looks wrong to me:

if(digitalRead(buttonState) == HIGH)

Should it be:

if(digitalRead(buttonPin) == HIGH)

There' s nothing syntactically wrong with that line, so the compiler won't complain.

First, to reply to Groove: Yes, that is the entire code. It should be a simple LED changing button code, where I should only have to press the push button once to turn it on and have it stay on until push it again to turn it off and have it stay off until the next button push, with a half a second delay for debouncing.

Secondly, to JohnLincoln:

The following line looks wrong to me:

if(digitalRead(buttonState) == HIGH)

Should it be:

if(digitalRead(buttonPin) == HIGH)

The reason I have it as "if(digitalRead(buttonState) == HIGH)" is because I have buttonState assigned to the buttonPin constant integer. I'll try changing it up and see if it works, but I thought i'd elaborate on why that line of code is written as such. But anyways, the digitalRead should be fine. My issue at the moment is with the ledValue. If I find out later that there's issues going on with the digitalRead, i'll take your advice and see if changing buttonState to buttonPin will fix it after the ledValue problem is solved.

Anyways, I appreciate all the feedback that I've been getting so far. I do appreciate all the help.

-Ocelot

You missed the point about the difference between buttonState and buttonPin in the context of a digitalRead.

True. Anyways, i'll make sure to look over it ASAP.

-Ocelot