error: 'class LCDKeypad' has no member named 'getKey' Error compiling.

#include <Wire.h>
#include <LiquidCrystal.h>
#include <LCDKeypad.h>

//define keycode for LCD push button
#define None 0
#define Select 1
#define Left 2
#define Up 3
#define Down 4
#define Right 5

LiquidCrystal lcd(8,9,4,5,6,7);
LCDKeypad keypad;

//define pin name
#define diy_pwm A2
#define pwm 3
#define dir 2
#define pot A1

void setup(){

lcd.begin (16,2);
lcd.clear();

pinMode(pwm,OUTPUT);
pinMode(dir,OUTPUT);
pinMode(diy_pwm,OUTPUT);
pinMode(pot,INPUT);
}

void loop(){
int localkey;
int pwm_value;
int reading=0;
int prev_reading = 0;
int output = 0;

lcd.setCursor(0,0);lcd.print("PWM:");
lcd.print(output);
lcd.setCursor(0,1);
lcd.print("DIR:");
lcd.print(digitalRead(dir));

while(1){
localkey = keypad.getKey();
if(localkey=Left){
digitalWrite(dir,digitalRead(dir));
lcd.setCursor(0,1);
lcd.print("DIR:");
lcd.print(digitalRead(dir));
delay(200);
}
reading=0;
for(int i=0; i<5; i++)
reading+=analogRead(pot);
reading/=5;
output=reading*0.2493;
if (reading!=prev_reading){
lcd.print("");
lcd.setCursor(0,0);
lcd.print("PWM:");
lcd.print(output);

prev_reading=reading;
}

analogWrite(pwm,output);
}
}

someone please help me SOS! i've tried everything but the error still pops up. i don't know what is the problem. I'm trying to drive a motor and control the speed by pressing the buttons on the keypad shield. i cannot get the input from the keypad shield SOS!! :disappointed_relieved: :disappointed_relieved:

Have a look at the LCDKeypad.h file. Does it have a method named getKey ? I think that it has a method named button to read a button pushed on the keypad.

Are there any examples of reading buttons included with the library download ?

I've attached the LCDKeypad library. There is some command button and they define the value for each button but i don't really understand. it seems like for this library i cannot use getKey()?

LCDKeypad.zip (2.66 KB)

it seems like for this library i cannot use getKey()?

That's right

You can do

int myButton = LCDKeypad.button();
Serial.println(myButton);

Depending in which button you press you should get a number printed, or -1 if no key is pressed.

purpralph:
I've attached the LCDKeypad library. There is some command button and they define the value for each button but i don't really understand. it seems like for this library i cannot use getKey()?

You can use what the library provides.
You cannot use what the library doesn't provide.
Easy as that.

The very limited library just provides a "button()" function to read the button currently pressed. No state change detection available.

The example program "GuessTheNumber" provides two blocking functions:

  • One function that blocks program execution until a button is pressed
  • One function that blocks program execution until no button is pressed

If you want such blocking 'busy waiting' input functions, you would have to include them in your sketch code:

int waitButton()
{
  int buttonPressed; 
  waitReleaseButton;
  lcd.blink();
  while((buttonPressed=lcd.button())==KEYPAD_NONE)
  {
  }
  delay(50);  
  lcd.noBlink();
  return buttonPressed;
}

void waitReleaseButton()
{
  delay(50);
  while(lcd.button()!=KEYPAD_NONE)
  {
  }
  delay(50);
}

Lookup the 'GuessTheNumber' example code how to use them for blocking program code that does 'busy waiting' until a button is pressed or released.

You can also use that for creating 'half-blocking' sketch code:

  • in your loop code wait for 'lcd.button()' return some pressed button
  • then block program execution using 'waitReleaseButton()' until the button is released

If that's enough using 'busy waiting', at least while waiting for the pressed button to be released, you can use the library like that.

But if you should need some kind of non-blocking state-change detection, because your program has to execute other tasks while waiting for button input (press as well as release), then you need a different programming logic approach.

Thank you guys so much for the response! I understood better now :smiley: