Reusing code meant for the Adafruit LCD with buttons shield

Dear all,
Please can you help me to understand what is required to re-write some code snippets meant for use with the lovely (but pricey) Adafruit i2c connected lcd shield? That shield uses an extended version of the LiquidCrystal library with extra functions including lcd.readButtons(). I want to replace the shield with a standard hitachi style lcd (that I can do) and 5 simple push switches. The switches are connected to pins declared:

// Setup button inputs

const int RightbuttonPin = 18;
const int DownbuttonPin = 19;
const int UpbuttonPin = 20;
const int ShiftbuttonPin = 21;
const int LeftbuttonPin = 22;

// Setup up values for button states

int BUTTON_UP = 0;
int BUTTON_DOWN = 0;
int BUTTON_SHIFT = 0;
int BUTTON_RIGHT = 0;
int BUTTON_LEFT = 0;

And initialised:

void setup()
{
  // Setup button inputs and activate internal pull up resistors

  pinMode(UpbuttonPin, INPUT_PULLUP);
  pinMode(ShiftbuttonPin, INPUT_PULLUP);
  pinMode(DownbuttonPin, INPUT_PULLUP);
  pinMode(LeftbuttonPin, INPUT_PULLUP);
  pinMode(RightbuttonPin, INPUT_PULLUP);

So that I can read the values in the normal way:

BUTTON_UP = digitalRead(UpbuttonPin);
BUTTON_DOWN = digitalRead(DownbuttonPin);
BUTTON_SHIFT = digitalRead(ShiftbuttonPin);
BUTTON_RIGHT = digitalRead(RightbuttonPin);
BUTTON_LEFT = digitalRead(LeftbuttonPin);

Which all works as intended. So here is the question. In the (Arduino Sous-Vide Cooker) What is Sous Vide? | Sous-vide controller powered by Arduino - The SousViduino! | Adafruit Learning System project the main loop waits for the ReadButtons function:

while(ReadButtons() != 0) {}

The original function is like this:

// ************************************************
// Check buttons and time-stamp the last press
// ************************************************
uint8_t ReadButtons()
{
  uint8_t buttons = lcd.readButtons();
  if (buttons != 0)
  {
    lastInput = millis();
  }
  return buttons;
}

And I have tried to emulate that by doing this:

// ************************************************
// Check buttons and time-stamp the last press
// ************************************************
uint8_t ReadButtons()
{
  
BUTTON_UP = digitalRead(UpbuttonPin);
BUTTON_DOWN = digitalRead(DownbuttonPin);
BUTTON_SHIFT = digitalRead(ShiftbuttonPin);
BUTTON_RIGHT = digitalRead(RightbuttonPin);
BUTTON_LEFT = digitalRead(LeftbuttonPin);

uint8_t buttons;
if (BUTTON_UP || BUTTON_DOWN || BUTTON_SHIFT ||BUTTON_RIGHT || BUTTON_LEFT){buttons = 1;}else{buttons = 0;}

  
  if (buttons != 0)
  {
    lastInput = millis();
  }
  return buttons;
  
}

But it never releases the main loop. Hoping someone can point me in the right direction (sorry for asking what I am sure is a silly question but have been searching and tinkering for hours now) Thank you!

Post your full code, not in parts. Make sure you add comments too.

This is the full (modified and thereby broken) code.
PART 1

// ************************************************
// Integral Tuning State
// UP/DOWN to change Ki
// RIGHT for Kd
// LEFT for Kp
// SHIFT for 10x tuning
// ************************************************
void TuneI()
{
 //  lcd.setBacklight(TEAL);
   lcd.print(F("Set Ki"));

   uint8_t buttons = 0;
   while(true)
   {
      buttons = ReadButtons();

      float increment = 0.01;
      if (buttons & BUTTON_SHIFT)
      {
        increment *= 10;
      }
      if (buttons & BUTTON_LEFT)
      {
         opState = TUNE_P;
         return;
      }
      if (buttons & BUTTON_RIGHT)
      {
         opState = TUNE_D;
         return;
      }
      if (buttons & BUTTON_UP)
      {
         Ki += increment;
         delay(200);
      }
      if (buttons & BUTTON_DOWN)
      {
         Ki -= increment;
         delay(200);
      }
      if ((millis() - lastInput) > 3000)  // return to RUN after 3 seconds idle
      {
         opState = RUN;
         return;
      }
      lcd.setCursor(0,1);
      lcd.print(Ki);
      lcd.print(" ");
      DoControl();
   }
}

// ************************************************
// Derivative Tuning State
// UP/DOWN to change Kd
// RIGHT for setpoint
// LEFT for Ki
// SHIFT for 10x tuning
// ************************************************
void TuneD()
{
//   lcd.setBacklight(TEAL);
   lcd.print(F("Set Kd"));

   uint8_t buttons = 0;
   while(true)
   {
      buttons = ReadButtons();
      float increment = 0.01;
      if (buttons & BUTTON_SHIFT)
      {
        increment *= 10;
      }
      if (buttons & BUTTON_LEFT)
      {
         opState = TUNE_I;
         return;
      }
      if (buttons & BUTTON_RIGHT)
      {
         opState = RUN;
         return;
      }
      if (buttons & BUTTON_UP)
      {
         Kd += increment;
         delay(200);
      }
      if (buttons & BUTTON_DOWN)
      {
         Kd -= increment;
         delay(200);
      }
      if ((millis() - lastInput) > 3000)  // return to RUN after 3 seconds idle
      {
         opState = RUN;
         return;
      }
      lcd.setCursor(0,1);
      lcd.print(Kd);
      lcd.print(" ");
      DoControl();
   }
}

// ************************************************
// PID COntrol State
// SHIFT and RIGHT for autotune
// RIGHT - Setpoint
// LEFT - OFF
// ************************************************
void Run()
{
   // set up the LCD's number of rows and columns: 
   lcd.print(F("Sp: "));
   lcd.print(Setpoint);
   lcd.write(1);
   lcd.print(F("C : "));

   SaveParameters();
   myPID.SetTunings(Kp,Ki,Kd);

   uint8_t buttons = 0;
   while(true)
   {
      setBacklight();  // set backlight based on state

      buttons = ReadButtons();
      if ((buttons & BUTTON_SHIFT) 
         && (buttons & BUTTON_RIGHT) 
         && (abs(Input - Setpoint) < 0.5))  // Should be at steady-state
      {
         StartAutoTune();
      }
      else if (buttons & BUTTON_RIGHT)
      {
        opState = SETP;
        return;
      }
      else if (buttons & BUTTON_LEFT)
      {
        opState = OFF;
        return;
      }
      
      DoControl();
      
      lcd.setCursor(0,1);
      lcd.print(Input);
      lcd.write(1);
      lcd.print(F("C : "));
      
      float pct = map(Output, 0, WindowSize, 0, 1000);
      lcd.setCursor(10,1);
      lcd.print(F("      "));
      lcd.setCursor(10,1);
      lcd.print(pct/10);
      //lcd.print(Output);
      lcd.print("%");

      lcd.setCursor(15,0);
      if (tuning)
      {
        lcd.print("T");
      }
      else
      {
        lcd.print(" ");
      }
      
      // periodically log to serial port in csv format
      if (millis() - lastLogTime > logInterval)  
      {
        Serial.print(Input);
        Serial.print(",");
        Serial.println(Output);
      }

      delay(100);
   }
}

// ************************************************
// Execute the control loop
// ************************************************
void DoControl()
{
  // Read the input:
  if (sensors.isConversionAvailable(0))
  {
    Input = sensors.getTempC(tempSensor);
    sensors.requestTemperatures(); // prime the pump for the next one - but don't wait
  }
  
  if (tuning) // run the auto-tuner
  {
     if (aTune.Runtime()) // returns 'true' when done
     {
        FinishAutoTune();
     }
  }
  else // Execute control algorithm
  {
     myPID.Compute();
  }
  
  // Time Proportional relay state is updated regularly via timer interrupt.
  onTime = Output; 
}

// ************************************************
// Called by ISR every 15ms to drive the output
// ************************************************
void DriveOutput()
{  
  long now = millis();
  // Set the output
  // "on time" is proportional to the PID output
  if(now - windowStartTime>WindowSize)
  { //time to shift the Relay Window
     windowStartTime += WindowSize;
  }
  if((onTime > 100) && (onTime > (now - windowStartTime)))
  {
     digitalWrite(RelayPin,HIGH);
  }
  else
  {
     digitalWrite(RelayPin,LOW);
  }
}

Part 2

// ************************************************
// Set Backlight based on the state of control
// ************************************************

// ?use this to activate high speed fan via pwm?

void setBacklight()
{
   if (tuning)
   {
   //   lcd.setBacklight(VIOLET); // Tuning Mode
   }
   else if (abs(Input - Setpoint) > 1.0)  
   {
   //   lcd.setBacklight(RED);  // High Alarm - off by more than 1 degree
   }
   else if (abs(Input - Setpoint) > 0.2)  
   {
  //    lcd.setBacklight(YELLOW);  // Low Alarm - off by more than 0.2 degrees
   }
   else
   {
   //   lcd.setBacklight(WHITE);  // We're on target!
   }
}

// ************************************************
// Start the Auto-Tuning cycle
// ************************************************

void StartAutoTune()
{
   // REmember the mode we were in
   ATuneModeRemember = myPID.GetMode();

   // set up the auto-tune parameters
   aTune.SetNoiseBand(aTuneNoise);
   aTune.SetOutputStep(aTuneStep);
   aTune.SetLookbackSec((int)aTuneLookBack);
   tuning = true;
}

// ************************************************
// Return to normal control
// ************************************************
void FinishAutoTune()
{
   tuning = false;

   // Extract the auto-tune calculated parameters
   Kp = aTune.GetKp();
   Ki = aTune.GetKi();
   Kd = aTune.GetKd();

   // Re-tune the PID and revert to normal control mode
   myPID.SetTunings(Kp,Ki,Kd);
   myPID.SetMode(ATuneModeRemember);
   
   // Persist any changed parameters to EEPROM
   SaveParameters();
}

// ************************************************
// Check buttons and time-stamp the last press
// ************************************************
uint8_t ReadButtons()
{
  
BUTTON_UP = digitalRead(UpbuttonPin);
BUTTON_DOWN = digitalRead(DownbuttonPin);
BUTTON_SHIFT = digitalRead(ShiftbuttonPin);
BUTTON_RIGHT = digitalRead(RightbuttonPin);
BUTTON_LEFT = digitalRead(LeftbuttonPin);

uint8_t buttons;
if (BUTTON_UP || BUTTON_DOWN || BUTTON_SHIFT ||BUTTON_RIGHT || BUTTON_LEFT){buttons = 1;}else{buttons = 0;}

  
  if (buttons != 0)
  {
    lastInput = millis();
  }
  return buttons;
  
}

// ************************************************
// Save any parameter changes to EEPROM
// ************************************************
void SaveParameters()
{
   if (Setpoint != EEPROM_readDouble(SpAddress))
   {
      EEPROM_writeDouble(SpAddress, Setpoint);
   }
   if (Kp != EEPROM_readDouble(KpAddress))
   {
      EEPROM_writeDouble(KpAddress, Kp);
   }
   if (Ki != EEPROM_readDouble(KiAddress))
   {
      EEPROM_writeDouble(KiAddress, Ki);
   }
   if (Kd != EEPROM_readDouble(KdAddress))
   {
      EEPROM_writeDouble(KdAddress, Kd);
   }
}

// ************************************************
// Load parameters from EEPROM
// ************************************************
void LoadParameters()
{
  // Load from EEPROM
   Setpoint = EEPROM_readDouble(SpAddress);
   Kp = EEPROM_readDouble(KpAddress);
   Ki = EEPROM_readDouble(KiAddress);
   Kd = EEPROM_readDouble(KdAddress);
   
   // Use defaults if EEPROM values are invalid
   if (isnan(Setpoint))
   {
     Setpoint = 60;
   }
   if (isnan(Kp))
   {
     Kp = 850;
   }
   if (isnan(Ki))
   {
     Ki = 0.5;
   }
   if (isnan(Kd))
   {
     Kd = 0.1;
   }  
}


// ************************************************
// Write floating point values to EEPROM
// ************************************************
void EEPROM_writeDouble(int address, double value)
{
   byte* p = (byte*)(void*)&value;
   for (int i = 0; i < sizeof(value); i++)
   {
      EEPROM.write(address++, *p++);
   }
}

// ************************************************
// Read floating point values from EEPROM
// ************************************************
double EEPROM_readDouble(int address)
{
   double value = 0.0;
   byte* p = (byte*)(void*)&value;
   for (int i = 0; i < sizeof(value); i++)
   {
      *p++ = EEPROM.read(address++);
   }
   return value;
}

Where is your loop function? And why are you still breaking up the code, if you want help I need to see the code in full, not parts. You can add an attachment under additional options at the bottom when you make a new reply.

Looking at your link, those buttons use one analog pin A0 to read the buttons. This is done with a resistor ladder, meaning the code itself is already designed to work with the resistor values. However your buttons are the basic one pin per button, so I have to ask how are your buttons wired? Are they normally High or Low, are you sure they have some stable connection to the board when the button is not press and the pin is floating?

I also see that you are not debouncing the buttons like you should nor are you checking to see if they are being held down or not. I'm guessing you are brand new to using an Arduino or maybe even coding altogether, but the Arduino software comes with examples you can play with, learn from and adapt to your code. There are quite a few things that need to be fixed, but seeing as your code mostly revolves are your buttons at the moment, I suggest you iron out their flaws first.

But it never releases the main loop.

Say what? I have no clue what this means.