我是c ++和arduino的新手,我想编写一个非常简单的类来改进交付的等待函数。但我得到一个我无法解决的错误:\也许你可以帮助我:) 错误是:
SmartDelay.cpp:13:7:错误:' lastMillis'在这方面没有申明 (对于每次使用' lastMillis'),错误会重复多次 这是头文件和cpp文件:
#ifndef smartDelay_H_
#define smartDelay_H_
#include "SmartDelay.cpp"
class SmartDelay {
public:
SmartDelay();
void reset();
void wait(long);
private:
long lastMillis;
};
#endif
CPP:
#include "smartDelay.h"
#include "Arduino.h"
SmartDelay::SmartDelay() { //Constructor
reset();
}
void SmartDelay::reset() {
lastMillis = -1;
}
void SmartDelay::wait(long time) { // memorizes the last millis and substracts it from the delay time to maintain constant rates
if (lastMillis != -1) {
delay(max(time - (millis() - lastMillis), 0));
} else {
delay(time);
}
lastMillis = millis();
}