I am trying to call the keypad function into my own library. Before this I had an error "Invalid use of non-static error member function" and have changed the function into a static function. However since the keypad function is non-static, it still does not run.
This is the error.
sketch\latch.cpp: In static member function 'static void latch::keypadEvent(KeypadEvent)': latch.cpp:18:11: error: invalid use of member 'latch::keypad' in static member function switch (keypad.getState()){ ^ In file included from sketch\latch.cpp:1:0: sketch\latch.h:20:12: note: declared here Keypad keypad; ^ exit status 1 invalid use of member 'latch::keypad' in static member function
My code
#include "latch.h"
latch doorlatch;
void setup(){
  doorlatch.begin(9600);
  }
 void loop(){
  doorlatch.main();
  }
h file
#include <Keypad.h>
#ifndef _latch_
#define _latch_
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class latch {
  public:
    latch();
    void begin(int baudrate);
    void main();
    static void keypadEvent(KeypadEvent input);
    Keypad keypad;
  private:
    const byte Rows = 4;
    const byte Cols = 4;
    char keys[4][4] = {
      {'1', '2', '3', 'A'},
      {'4', '5', '6', 'B'},
      {'7', '8', '9', 'C'},
      {'*', '0', '#', 'D'}
    };
    byte rowPins[4] = {7, 6, 5, 4};
    byte colPins[4] = { 11, 10, 9, 8 };
};
#endif
cpp file
latch::latch():keypad( makeKeymap(keys), rowPins, colPins, Rows, Cols ) {
}
void latch::begin(int baudrate){
  Serial.begin(baudrate);
  keypad.addEventListener(keypadEvent);
}
void latch::main(){
  keypad.getKey();
}
void latch::keypadEvent(KeypadEvent input){
  switch (keypad.getState()){
  case PRESSED:
  Serial.print("Enter: ");
  Serial.println(input);
  delay(10);
  }
}
Can someone help me solve this ? Or should I use a different method ? such as declaring it as friend ?
 
    