毫();Arduino "out of scope"



我已经建立了一个自定义时钟/气象站。但出于一些目的,我希望能够在我的代码中运行计时器。我以前在c++中使用SDL库(SDL_GetTicks())做过很多次。我知道我可以用同样的方式在Arduino IDE中使用millis()。

所以我只是复制粘贴了我以前用于SDL程序的计时器类的代码,并将SDL_GetTicks()替换为millis()。

但是,现在它说millis()超出了作用域。我不明白?我不允许在成员变量中使用millis吗?

#include "Timer.h"
namespace Timer
{
void Timer::startTimer() 
{
if (!this->timerStarted) 
{ 
this->current_time = millis(); 
this->timerStarted = true; 
}
} 
unsigned int Timer::showTimePassed() 
{ 
this->time_passed = millis(); 
return this->time_passed - this->current_time; 
}
bool Timer::ifTimePassed(unsigned int timePassed)
{
this->last_time = millis();
if (!this->timerStarted)
{
this->current_time = millis();
this->timerStarted = true;
}
if (this->timerStarted == true && this->last_time >= this->current_time + timePassed)
{
timerStarted = false;
return true;
}
return false;
}
void Timer::setLoop()
{
this->timerStarted = true;
this->last_time = this->current_time;
this->current_time = millis();
this->time_passed = this->current_time - this->last_time;
}
unsigned int Timer::getLoopTime()
{
return this->time_passed;
}
}

您必须在头文件中包含arduino.h,这应该可以解决问题。

# include & lt; Arduino.h>

最新更新