lcd error

this code worked until I added the last two "if" statements, now when button is pressed, screen goes blank, please help!

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int seconds = 0;
int minutes = 1;
int hours = 1;
int trim_s = 0;
int trim_m = 0;
int trim_h = 0;
int am_pm = 1;

void setup() {
  lcd.begin(16, 2);
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  Serial.begin (9600);
}

void loop() {
  lcd.setCursor(0, 0);
  seconds = (millis()/1000)+ trim_s;
  lcd.print(hours);
  lcd.print(":");
  lcd.print(minutes);
  lcd.print(":");
  lcd.print(seconds);
  lcd.print(" ");
  if (am_pm == 1){
    lcd.print("AM");
  }
  else{
  lcd.print("PM");
  }
  if (seconds > 59){
    seconds = 0;
    trim_s = trim_s -60;
    minutes = minutes + 1;
    lcd.setCursor(8, 0);
    lcd.print(" ");
    lcd.setCursor(9, 0);
    lcd.print(" ");
    lcd.setCursor(10, 0);
    lcd.print(" ");
  }
  else{}
  if (minutes >59){
    minutes = 0;
    hours = hours + 1;
    lcd.setCursor(6, 0);
    lcd.print(" ");
    lcd.setCursor(5, 0);
    lcd.print(" ");
    lcd.setCursor(9, 0);
    lcd.print(" ");
    lcd.setCursor(10, 0);
    lcd.print(" ");
  }
  if (hours > 12){
    hours = 1;
    lcd.setCursor(7, 0);
    lcd.print(" ");
    lcd.setCursor(8, 0);
    lcd.print(" ");
    lcd.setCursor(9, 0);
    lcd.print(" ");
    lcd.setCursor(10, 0);
    lcd.print(" ");
    if (am_pm == 1){
      am_pm = 0;
    }
    else{
      am_pm = 1;
    }
    digitalRead (8);
    digitalRead (9);
  }
  if (8 == HIGH){
    hours = (hours + 1);
    Serial.println("1");
  }
      if (9 == HIGH){
    minutes = (minutes + 1);
    Serial.println("2");
  }
}
 pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
if (8 == HIGH){
    hours = (hours + 1);
    Serial.println("1");
  }
      if (9 == HIGH){
    minutes = (minutes + 1);
    Serial.println("2");
  }

How are your buttons wired, and how do you make them HIGH? Typically you would read buttons with INPUT. It is usually easier to wire the switches so when closed they connect the pin to ground, and make the pin INPUT_PULLUP. It will go LOW when the button is pressed.

You also want to change the sketch so that you detect when the button is pushed and the pin changes state and only increment the variable once per press. Otherwise, you will be cycling through the loop many many times per second, and your increments wont be controlled.

(using breadboard "GPS") power to F-29; switch form F-29 to F-27; 10k ohm resistor from H-27 to ground; jumper from G-27 to pin 8.
i also changed the HIGH to LOW as per request, and nothing changed.
How would one go about making it change only incrementally when a button is pressed without delays (because they would interfere with the timekeeping) ?

(using breadboard "GPS") power to F-29; switch form F-29 to F-27; 10k ohm resistor from H-27 to ground; jumper from G-27 to pin 8.

You'll have to provide a sketch. Did you change pin 8 and 9 to inputs? I also just noticed that there is no digitalRead of pin 8 and 9 to detect their state.

if (digitalRead(8) == HIGH){
    hours = (hours + 1);
    Serial.println("1");
  }
      if (digitalRead(9) == HIGH){
    minutes = (minutes + 1);
    Serial.println("2");
  }

I would recommend that you forget about the clock for a while, and write a small sketch that just reads the buttons with digitalRead and you can confirm your wiring and the ability to read buttons. Then you can work on detcting when the button has become pressed rather than when it is pressed. There are lots of examples around on reading buttons which Mr Google can help you find.

Finally, you can integrate the clock.

ok, so now it just rapidly changes, (which is to be expected) how can I make it go only one number per press
if button is held down for a few soconds, screen blanks
changes were:

unsigned long int trim_s = 0;

if (digitalRead(8) == HIGH){
hours = (hours + 1);
Serial.println("1");
}
if (digitalRead(9) == HIGH){
minutes = (minutes + 1);
Serial.println("2");

srry for emoticon, that line is
if (digitalRead( 8 ) == HIGH){

even when lcd is blank, serial port still repkies with the 1's and 2's when buttons are pressed

Take a look at this tutorial on button state change and see what you can come up with.

You may also have to do some Google search on "debounce" and implement those techniques if you get multiple increments with each push when you are using the state change.

I would also try to write your code so that the display only changes every second or so, and not every time through the loop. You will use the techniques of "blink without delay".

When you have some new code, please post the full code within the code tags, which are found in the icon which looks like a with <>.

srry for emoticon, that line is
if (digitalRead( 8 ) == HIGH){

You won't get the emoticon, and your code will be much easier to read in general, if you use code tags for your code.

Just go back to each of your previous posts, highlight the part that is code, and click on the 'code' button which is currently the seventh one from the right. It looks like a scroll with < and > .

Don

Here is the current code

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long int seconds = 0;
unsigned long int minutes = 35;
unsigned long int hours = 9;
unsigned long int trim_s = 0;
unsigned long int trim_m = 0;
unsigned long int trim_h = 0;
unsigned long int am_pm = 2;
unsigned long time = 0;
long debounce = 100;

void setup() {
  lcd.begin(16, 2);
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  Serial.begin (9600);
}

void loop() {
  time = millis(); 
  lcd.setCursor(0, 0);
  seconds = (millis()/1000)- trim_s;
  lcd.print(hours);
  lcd.print(":");
  lcd.print(minutes);
  lcd.print(":");
  lcd.print(seconds);
  lcd.print(" ");
  if (am_pm == 1){
    lcd.print("AM");
  }
  else{
  lcd.print("PM");
  }
  if (seconds > 59){
    seconds = 0;
    trim_s = trim_s +60;
    minutes = minutes + 1;
    lcd.setCursor(8, 0);
    lcd.print(" ");
    lcd.setCursor(9, 0);
    lcd.print(" ");
    lcd.setCursor(10, 0);
    lcd.print(" ");
  }
  else{}
  if (minutes >59){
    minutes = 0;
    hours = hours + 1;
    lcd.setCursor(6, 0);
    lcd.print(" ");
    lcd.setCursor(5, 0);
    lcd.print(" ");
    lcd.setCursor(9, 0);
    lcd.print(" ");
    lcd.setCursor(10, 0);
    lcd.print(" ");
  }
  if (hours > 12){
    hours = 1;
    lcd.setCursor(7, 0);
    lcd.print(" ");
    lcd.setCursor(8, 0);
    lcd.print(" ");
    lcd.setCursor(9, 0);
    lcd.print(" ");
    lcd.setCursor(10, 0);
    lcd.print(" ");
    if (am_pm == 1){
      am_pm = 0;
    }
    else{
      am_pm = 1;
    }
    digitalRead (8);
    digitalRead (9);
  }
  time = millis(); 
  if (digitalRead(8) == HIGH && millis() - time > debounce){
    hours = (hours + 1);
    Serial.println("1");
  }
  time = millis(); 
      if (digitalRead(9) == HIGH && millis() - time > debounce){
    minutes = (minutes + 1);
    Serial.println("2");
  }
}

The problems with this new debounced code are as follows:
LCD is still going blank after a button press,
and the serial port is not reporting the "1" or "2" indicating a button press.
Any help would be appreciated, Thank you.

the serial port is not reporting the "1" or "2" indicating a button press.

Your debounce code is not correct. You are setting time = millis() right before you enter the if() so millis() -time will never be equal to the interval.Take another look at the debounce tutorial http://arduino.cc/en/Tutorial/Debounce and the 02 Digital examples in the IDE.

LCD is still going blank after a button press,

You really need to show us the wiring of how you are using the buttons on an output pin. This has bothered me from the beginning and I have this notion that you are connecting the pin to ground and I suspect you are dragging down the power supply. You are using the button state as an input for your program. Configure the pin as an input with input_pullup and connect the pin through the button to ground. The digitalRead will be high with no press, and low with a press.

the push buttons are and have been set up in the exact same way as the example on http://arduino.cc/en/Tutorial/Debounce
Thank you for your responce, I am looking over the debounce code right now.........

the push buttons are and have been set up in the exact same way as the example on http://arduino.cc/en/Tutorial/Debounce

OK, and in that example, the button pin is configured as an INPUT.

I have integrated the two codes, here is the ending of the new code

  reading = digitalRead(buttonPin);
  if (reading != lastButtonState) {
   lastDebounceTime = millis();
  } 
  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (reading != buttonState) {
      buttonState = reading;
      if (buttonState == HIGH) {
            hours = (hours + 1);
            Serial.println("1");
      }
    }
  }

the problems still persist,

LCD is still going blank after a button press,
and the serial port is not reporting the "1" or "2" indicating a button press.

(no other changes were made to the original code)

reading was declared as an int. at the beginning so that the code would upload.

Please post the complete code.

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long int seconds = 0;
unsigned long int minutes = 35;
unsigned long int hours = 9;
unsigned long int trim_s = 0;
unsigned long int trim_m = 0;
unsigned long int trim_h = 0;
unsigned long int am_pm = 2;
unsigned long time = 0;
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;    
const int buttonPin = 8;
const int buttonPin2 = 9;
int reading;


void setup() {
  lcd.begin(16, 2);
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  Serial.begin (9600);
}

void loop() {
  time = millis(); 
  lcd.setCursor(0, 0);
  seconds = (millis()/1000)- trim_s;
  lcd.print(hours);
  lcd.print(":");
  lcd.print(minutes);
  lcd.print(":");
  lcd.print(seconds);
  lcd.print(" ");
  if (am_pm == 1){
    lcd.print("AM");
  }
  else{
  lcd.print("PM");
  }
  if (seconds > 59){
    seconds = 0;
    trim_s = trim_s +60;
    minutes = minutes + 1;
    lcd.setCursor(8, 0);
    lcd.print(" ");
    lcd.setCursor(9, 0);
    lcd.print(" ");
    lcd.setCursor(10, 0);
    lcd.print(" ");
  }
  else{}
  if (minutes >59){
    minutes = 0;
    hours = hours + 1;
    lcd.setCursor(6, 0);
    lcd.print(" ");
    lcd.setCursor(5, 0);
    lcd.print(" ");
    lcd.setCursor(9, 0);
    lcd.print(" ");
    lcd.setCursor(10, 0);
    lcd.print(" ");
  }
  if (hours > 12){
    hours = 1;
    lcd.setCursor(7, 0);
    lcd.print(" ");
    lcd.setCursor(8, 0);
    lcd.print(" ");
    lcd.setCursor(9, 0);
    lcd.print(" ");
    lcd.setCursor(10, 0);
    lcd.print(" ");
    if (am_pm == 1){
      am_pm = 0;
    }
    else{
      am_pm = 1;
    }
    digitalRead (8);
    digitalRead (9);
  }
  time = millis(); 
  reading = digitalRead(buttonPin);
  if (reading != lastButtonState) {
   lastDebounceTime = millis();
  } 
  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (reading != buttonState) {
      buttonState = reading;
      if (buttonState == HIGH) {
            hours = (hours + 1);
            Serial.println("1");
      }
    }
  }
   reading = digitalRead(buttonPin2);
  if (reading != lastButtonState) {
   lastDebounceTime = millis();
  } 
  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (reading != buttonState) {
      buttonState = reading;
      if (buttonState == HIGH) {
        minutes = (minutes + 1);
        Serial.println("2");
      }
    }
  }
}

Here is a revision of your code which increments hours and minutes by one with a button press. I've made the buttons INPUT_PULLUP, added additional state variables for the second button, taken out some unused or unecessary variables, and revised the logic slightly.

//My set up for I2C lcd
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);

//#include <LiquidCrystal.h>
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long int seconds = 0;
unsigned long int minutes = 35;
unsigned long int hours = 9;
unsigned long int trim_s = 0;
unsigned long int trim_m = 0;
unsigned long int trim_h = 0;
unsigned long int am_pm = 2;
//unsigned long time = 0; variable not used
int buttonState = HIGH;//button not pressed, INPUT_PULLUP
int lastButtonState = HIGH;//button not pressed, INPUT_PULLUP
//add state variables for second button
int buttonState2 = HIGH;//button not pressed, INPUT_PULLUP
int lastButtonState2 = HIGH;//button not pressed, INPUT_PULLUP
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
const int buttonPin = 8;
const int buttonPin2 = 9;
int reading;
int reading2;//add second pin digitalRead


void setup() {
  lcd.begin(16, 2);
  //pinMode (8, OUTPUT);
  //pinMode (9, OUTPUT);
  pinMode(8, INPUT_PULLUP);//pins changed to INPUT with internal PULLUP
  pinMode(9, INPUT_PULLUP);//pins changed to INPUT with internal PULLUP

}

void loop() {
  //time = millis();
  lcd.setCursor(0, 0);
  seconds = (millis() / 1000) - trim_s;
  lcd.print(hours);
  lcd.print(":");
  lcd.print(minutes);
  lcd.print(":");
  lcd.print(seconds);
  lcd.print(" ");
  if (am_pm == 1) {
    lcd.print("AM");
  }
  else {
    lcd.print("PM");
  }
  if (seconds > 59) {
    seconds = 0;
    trim_s = trim_s + 60;
    minutes = minutes + 1;
    lcd.setCursor(8, 0);
    lcd.print(" ");
    lcd.setCursor(9, 0);
    lcd.print(" ");
    lcd.setCursor(10, 0);
    lcd.print(" ");
  }
  else {}
  if (minutes > 59) {
    minutes = 0;
    hours = hours + 1;
    lcd.setCursor(6, 0);
    lcd.print(" ");
    lcd.setCursor(5, 0);
    lcd.print(" ");
    lcd.setCursor(9, 0);
    lcd.print(" ");
    lcd.setCursor(10, 0);
    lcd.print(" ");
  }
  if (hours > 12) {
    hours = 1;
    lcd.setCursor(7, 0);
    lcd.print(" ");
    lcd.setCursor(8, 0);
    lcd.print(" ");
    lcd.setCursor(9, 0);
    lcd.print(" ");
    lcd.setCursor(10, 0);
    lcd.print(" ");
    if (am_pm == 1) {
      am_pm = 0;
    }
    else {
      am_pm = 1;
    }
    //digitalRead (8);//not needed
    //digitalRead (9);//not needed
  }
  //time = millis();//unecessary

  //routine to increment hours
  reading = digitalRead(buttonPin);
  if (reading != lastButtonState) {
    lastDebounceTime = millis();
  }
  if ((millis() - lastDebounceTime) > debounceDelay) {

    if (reading != buttonState) {
      buttonState = reading;
      //logic to increment once on button press
      if (buttonState == LOW && lastButtonState == LOW) {
        {
          hours = (hours + 1);
        }
      }
    }
  }
  lastButtonState = reading;

  //routine to increment minutes
  reading2 = digitalRead(buttonPin2);
  if (reading2 != lastButtonState2) {
    lastDebounceTime = millis();
  }
  if ((millis() - lastDebounceTime) > debounceDelay) {

    if (reading2 != buttonState2) {
      buttonState2 = reading2;

      //logic to increment once on button press
      if (buttonState2 == LOW && lastButtonState2 == LOW) {
        {
          minutes = (minutes + 1);
        }
      }
    }
  }
  lastButtonState2 = reading2;
}

compilation errrors are:

sketch_feb20a:4: error: 'LiquidCrystal_I2C' does not name a type
sketch_feb20a.ino: In function 'void setup()':
sketch_feb20a:30: error: 'lcd' was not declared in this scope
sketch_feb20a.ino: In function 'void loop()':
sketch_feb20a:40: error: 'lcd' was not declared in this scope

By the way, I am using an arduino uno.