Moving a character around an LCD screen - is there a better way? I have some basic programming experience but I am a novice at both C and Arduino.

I messed around with the example LCD code to try to move a character around with the onboard keypad. I also wanted the actual move to occur only once the button is released, like you would expect from a keypad.

The code works, but I have a feeling all the empty WHILE loops inside the main loop() function I used are not the best practice.. :)

How did I do? Is there a more convenient/elegant solution I missed and can learn from?

Thanks, and sorry for the messy code!

void loop()
{
  lcd.clear();
  lcd.setCursor(posCol,posRow);      //initialized beforehand
  lcd.print("O");                    //random char to move
  lcdOld = btnNONE;

  while (read_LCD_buttons() == btnNONE)     //do nothing while nothing is pressed
  {
  }

  lcdOld = read_LCD_buttons();

  while (read_LCD_buttons() == lcdOld)     //do nothing while button is down
  {
  }

  switch (lcdOld)               // depending on which button was pushed, we perform an action
   {
   case btnRIGHT:
     {
     posCol++;
     break;
     }
   case btnLEFT:
     {
     posCol--;
     break;
     }
   case btnUP:
     {
     if (posRow == 1)
     {
        posRow = 0;
        break;
     }
     else
     {
     break;
     }
     }
   case btnDOWN:
     {
     if (posRow == 0)
     {
        posRow = 1;
        break;
     }
     else
     {
     break;
     }
     }
   case btnSELECT:
     {
     break;
     }
     case btnNONE:
     {
     break;
     }
 }  
}
You could encapsulate the logic of detecting a button release into its
own function:

// Return the button that was just released, or btnNONE.
int releasedButton()
{
    static int last_button = btnNONE;
    int previous_button = last_button;
    last_button = read_LCD_buttons();
    if (last_button == btnNONE)
        return previous_button;
    else
        return btnNONE;
}


Then the logic in the loo gets simplified:

void loop()
{
    switch (releasedButton()) {
        ...
    }
}