Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 米利斯();“阿杜伊诺”;“超出范围”;_C++_Scope_Arduino Ide - Fatal编程技术网

C++ 米利斯();“阿杜伊诺”;“超出范围”;

C++ 米利斯();“阿杜伊诺”;“超出范围”;,c++,scope,arduino-ide,C++,Scope,Arduino Ide,我已经建立了一个定制的时钟/气象站。但出于几个目的,我希望能够在代码中运行计时器。我以前在C++中用SDL LIB(SDLGGETICKSK())做了很多次。我知道我可以在Arduino IDE中使用millis()以同样的方式获得滴答声 因此,我只是复制粘贴了以前用于SDL程序的计时器类的代码,并将SDL_GetTicks()替换为millis() 然而,现在它说millis()超出了范围。我不明白? 我不允许在成员变量中使用毫秒吗 #include "Timer.h"

我已经建立了一个定制的时钟/气象站。但出于几个目的,我希望能够在代码中运行计时器。我以前在C++中用SDL LIB(SDLGGETICKSK())做了很多次。我知道我可以在Arduino IDE中使用millis()以同样的方式获得滴答声

因此,我只是复制粘贴了以前用于SDL程序的计时器类的代码,并将SDL_GetTicks()替换为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

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


#include

我确信您可以在类方法中使用函数
millis
。请您引用准确的错误消息,这总是有帮助的,并指出错误消息适用于代码的哪一行。我确信您可以在类方法中使用函数
millis
。您能否引用准确的错误消息,这总是有帮助的,并指出错误消息适用于代码的哪一行。