If statement not carried out; please help

Need help with the if statement below which is not acted upon in this loop. Can't figure out why!Thank-you

unsigned long previousMillis = 0;

void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("# de pulse:"); // initialize the button pin as a input: pinMode(buttonPin, INPUT); // initialize the LED as an output: pinMode(ledPin, OUTPUT); // initialize serial communication: Serial.begin(9600); }

void loop() { unsigned long currentMillis = millis(); // read the pushbutton input pin: buttonState = digitalRead(buttonPin); // compare the buttonState to its previous state if (buttonState != lastButtonState) { // if the state has changed, increment the counter if (buttonState == HIGH) { // if the current state is HIGH then the button // wend from off to on: buttonPushCounter++; lcd.setCursor(0, 0); lcd.print(buttonPushCounter); // save the last time you blinked the LED //lastButtonState = buttonState; previousMillis = currentMillis; } } if (currentMillis - previousMillis > interval) { digitalWrite(ledPin, HIGH); lcd.setCursor(0, 1); lcd.print(buttonPushCounter); buttonPushCounter = 0; }

You never specify which if statement isn't carrying out, but I'll assume its the first one:

lastButtonState is never declared, nor is its value ever updated.

Also a good read: How to use this forum

Please post ALL your code. Pleas use code tags