Programming assistance with a servo

I am trying to program a servo that will move from 0 deg to 90 deg when button 1 is pressed and back to 0 deg when button 2 is pressed. I also have an LCD in the program but it is working ok. The switches I have wired are tied high and get pulled to ground when I press the buttons. The servo program itself works fine when it is set up as an individual sketch. It wasn’t until I added the LCD part of the program when it stopped working. Could anyone add some insight as to why this might be occurring?

I am using a Sparkfun LCD serial kit. I currently have buttons 1 and 2 on D12 and D13 and the servo on D11.

The code for both the servo and the LCD are pieced together from other sources.

Thank you.

#include <LiquidCrystal.h>
#include <EEPROM.h>
#include <Servo.h>

// --- EEPROM ADDRESS DEFINITIONS
#define LCD_BACKLIGHT_ADDRESS 1 // EEPROM address for backlight setting
#define BAUD_ADDRESS 2 // EEPROM address for Baud rate setting
#define SPLASH_SCREEN_ADDRESS 3 // EEPROM address for splash screen on/off
#define ROWS_ADDRESS 4 // EEPROM address for number of rows
#define COLUMNS_ADDRESS 5 // EEPROM address for number of columns

// --- SPECIAL COMMAND DEFINITIONS
#define BACKLIGHT_COMMAND 128 // 0x80
#define SPECIAL_COMMAND 254 // 0xFE
#define BAUD_COMMAND 129 // 0x81

// --- ARDUINO PIN DEFINITIONS
uint8_t RSPin = 2;
uint8_t RWPin = 3;
uint8_t ENPin = 4;
uint8_t D4Pin = 5;
uint8_t D5Pin = 6;
uint8_t D6Pin = 7;
uint8_t D7Pin = 8;
uint8_t BLPin = 9;

char inKey; // Character received from serial input
uint8_t Cursor = 0; // Position of cursor, 0 is top left, (rows*columns)-1 is bottom right
uint8_t LCDOnOff = 1; // 0 if LCD is off
uint8_t blinky = 0; // Is 1 if blinky cursor is on
uint8_t underline = 0; // Is 1 if underline cursor is on
uint8_t splashScreenEnable = 1; // 1 means splash screen is enabled
uint8_t rows = 2; // Number rows, will be either 2 or 4
uint8_t columns = 16; // Number of columns, will be 16 or 20
uint8_t characters; // rows * columns

// initialize the LCD at pins defined above
LiquidCrystal lcd(RSPin, RWPin, ENPin, D4Pin, D5Pin, D6Pin, D7Pin);

int press1 = 0;
int press2 = 0;
Servo servo1;


void setup(){
  // initialize the serial communications:
  setBaudRate(EEPROM.read(BAUD_ADDRESS));
  
  // Read rows and columns from EEPROM
  // Will default to 2x16, if not previously set
  rows = EEPROM.read(ROWS_ADDRESS);
  if (rows != 4)
    rows = 2;
  columns = EEPROM.read(COLUMNS_ADDRESS);
  if (columns != 20)
    columns = 16;
  
  // set up the LCD's number of rows and columns:
  lcd.begin(columns, rows);
  
  // Set up the backlight
  pinMode(BLPin, OUTPUT);
  setBacklight(EEPROM.read(LCD_BACKLIGHT_ADDRESS));
  
   pinMode(12, INPUT);
  pinMode(13, INPUT);
  servo1.attach(11);
  digitalWrite(12, HIGH); //enable pullups to make pin high
  digitalWrite(13, HIGH); //enable pullups to make pin high
  
}


void loop()
{
   
   press1 = digitalRead(12);
  if (press1 == LOW);
  {
    servo1.write(90);

  }    
  
  press2 = digitalRead(13);
  if (press2 == LOW);
  {
    servo1.write(05);
  }
  
  lcd.print("Test 1");
  delay(5000);
 lcd.setCursor(0,1);
lcd.print("Test 2");
delay(5000);
lcd.clear();

lcd.print("Test 3");
delay(5000);
lcd.clear();

lcd.print("Test 4");
lcd.setCursor(0,1);
lcd.print("Test 5");
delay(5000);
lcd.clear();
    
}



/* ----------------------------------------------------------
LCDDisplay() receives a single character and displays it
depending on what value is in Cursor. We also do a bit of
manipulation on Cursor, if it is beyond the screen size.
Finally the Cursor is advanced one value, before the function
is exited.
----------------------------------------------------------*/
void LCDDisplay(char character)
{
  int currentRow = 0;
  characters = rows * columns;
  
  // If Cursor is beyond screen size, get it right
  while (Cursor >= characters)
    Cursor -= characters;
  while (Cursor < 0)
    Cursor += characters;
  
  if (Cursor >= columns)
    currentRow = Cursor/columns;
    
  lcd.setCursor(Cursor%columns, currentRow);
  lcd.write(character);
  
  Cursor++;
}

/* ----------------------------------------------------------
setBacklight() is called from SpecialCommands(). It receives
a backlight setting between 0 and 255. The backlight is set
accordingly (via analogWrite()). Before exit the new backlight
value is written to EEPROM.
----------------------------------------------------------*/
void setBacklight(uint8_t backlightSetting)
{
  analogWrite(BLPin, backlightSetting);
  EEPROM.write(LCD_BACKLIGHT_ADDRESS, backlightSetting);
}

/* ----------------------------------------------------------
setBaudRate() is called from SpecialCommands(). It receives
a baud rate setting balue that should be between 0 and 10.
The baud rate is then set accordingly, and the new value is
written to EEPROM. If the EEPROM value hasn't been written
before (255), this function will default to 9600. If the value
is out of bounds 10<baud<255, no action is taken.
----------------------------------------------------------*/
void setBaudRate(uint8_t baudSetting)
{
  // If EEPROM is unwritten (0xFF), set it to 9600 by default
  if (baudSetting==255)
    baudSetting = 4;
    
  switch(baudSetting)
  {
    case 0:
      Serial.begin(300);
      break;
    case 1:
      Serial.begin(1200);
      break;
    case 2:
      Serial.begin(2400);
      break;
    case 3:
      Serial.begin(4800);
      break;
    case 4:
      Serial.begin(9600);
      break;
    case 5:
      Serial.begin(14400);
      break;
    case 6:
      Serial.begin(19200);
      break;
    case 7:
      Serial.begin(28800);
      break;
    case 8:
      Serial.begin(38400);
      break;
    case 9:
      Serial.begin(57600);
      break;
    case 10:
      Serial.begin(115200);
      break;
  }
  if ((baudSetting>=0)&&(baudSetting<=10))
    EEPROM.write(BAUD_ADDRESS, baudSetting);
}

You don’t say which board you are using but whatever else is going on using the Servo library prevents the use of PWM on pins 9 and 10 on boards other than the Mega so
uint8_t BLPin = 9;and  analogWrite(BLPin, backlightSetting);won’t work correctly.

Your real problem with controlling the servo is in these 2 lines

  if (press1 == LOW);
  if (press2 == LOW);

Study them carefully and compare them with

  if (Cursor >= columns)

The board I'm using is the Sparkfun LCD serial kit. It uses ATmega328.

Pin 9 is used by the LCD. I have the servo connected to D11.

Pin 9 is used by the LCD.

But you are trying to output a PWM signal to it which won't work with the servo attached. From http://arduino.cc/en/reference/servo

On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins

What about the dodgy if command lines ?

I guess I'm a little confused. I read what you put that PWM on pins 9 and 10 will be disabled with the servo library, but the kit I'm using already have pins 2-9 set for the LCD. So are you saying I can't use pin 9 or I can't use a servo with this configuration?

Here is the kit I got https://www.sparkfun.com/products/10097

I apologize, I'm really new at this and a lot of the code is still Greek to me.

You cannot use the standard servo library if you need to output a PWM signal on pn 9. There is an alternative servo library (ServoTimer2) that does not interfere with PWM on that pin but you will need to download and install it.