【发布时间】:2019-03-11 01:22:34
【问题描述】:
我正在尝试在另一个库中使用键盘库。但是,我收到“无效使用非静态错误成员函数”错误。我认为将函数更改为静态类型可以解决错误,但键盘库中的函数不是静态的,会导致更多错误。
这是没有将函数更改为静态无效的错误
sketch\latch.cpp: In member function 'void latch::begin(int)':
latch.cpp:10:38: error: invalid use of non-static member function
keypad.addEventListener(keypadEvent);
^
exit status 1
invalid use of non-static member function
------------main.ino--------------
#include "latch.h"
latch doorlatch;
void setup(){
doorlatch.begin(9600);
}
void loop(){
doorlatch.main();
}
-----------cpp.h文件------------
#include "latch.h"
#include "Arduino.h"
latch::latch():keypad( makeKeymap(keys), rowPins, colPins, Rows, Cols ) {
}
void latch::begin(int baudrate){
Serial.begin(baudrate);
Serial.println("Latch library created");
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);
}
}
------------h 文件-------------
#include <Keypad.h>
#ifndef _latch_
#define _latch_
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class latch {
public:
latch();
void keypadEvent(KeypadEvent input);
void begin(int baudrate);
void main();
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
【问题讨论】:
标签: arduino