LCD keypad button debounce

Hey there,

I’m trying to debounce the buttons for a dfrobot LCD keypad.

I’m using a library to control key presses and I think that might make it harder, i did it this way to cut down on coding.

I’m also going to have to come up with something instead of having a delay, but hopefully debouncing will help with that.

Also if anyone could help me with another problem of when i’m cycling through the menu after the last case 7 it doesn’t go back to home screen but to calibration instead. then you have to go from calibration and put up to get back to the home screen.

#include <LiquidCrystal.h>
#include "LCDKeypad.h"
LCDKeypad lcd;

int mainControl = 0;
int mainList = 0;

void setup() {
   
  lcd.begin(16, 2);               // start the library
}

void loop() {
  //main menu

int button = lcd.button();

  if (mainList < 0 || mainList > 8) {
   mainList = 0;}
   
   
    switch (button) {

    // Right button was pushed
    case KEYPAD_UP:
      mainList--;
      lcd.clear();
      break;

    // Left button was pushed
    case KEYPAD_DOWN:
      mainList++;
      lcd.clear();
      break;

    case KEYPAD_SELECT:
      break;

    case KEYPAD_RIGHT:
      break;
      
    case KEYPAD_NONE:
      break;
    }

    switch (mainList){
    case 0:
      //idle screen, repeatedly printing pH and CF
      lcd.home();
      lcd.print("Home Screen");
      delay(150);
      break;

    case 1:
      lcd.home();
      lcd.print("Calibration");
      delay(150);
      break;

    case 2:
      lcd.home();
      lcd.print("Set temperature");
      delay(150);
      break;

    case 3:
      lcd.home();
      lcd.print("Set alarm");
      delay(150);
      break;

    case 4:
      lcd.home();
      lcd.print("Titration curve");
      delay(150);
      break;

    case 5:
      lcd.home();
      lcd.print("Measure");
      lcd.setCursor(0, 1);
      lcd.print("over time");
      delay(150);
      break;

    case 6:
      lcd.home();
      lcd.print("Download data");
      delay(150);
      break;

    case 7:
      lcd.home();
      lcd.print("Backlight");
      delay(150);
      break;
      }
   }

Thanks very much

Doesn't the class have any debounced button functions? Maybe you just glossed over them. Any links to example code or the library would help.

aarg:
Doesn’t the class have any debounced button functions? Maybe you just glossed over them. Any links to example code or the library would help.

Hi aarg,

This is the library that i used for the LCD shield.

Actually that wasn't the library i was using because when i tried the keywords for the debouncing it didn't work. so I have downloaded this new library and i'm going to try again.

Any ideas on why the menu doesn't go back to the home screen and jumps straight to "calibrate"?

Its ok. The new library seems to have fixed my problems. The old library i was using didn't have built in debouncing like this one does.

Thanks aarg for the push in the right direction.