I have build a custom clock / weatherstation. But for a couple of purposes I wanna be able to run timers inside my code. I have done this many times before in C++ with the SDL lib (SDL_GetTicks()). And I know I can get ticks the same way in the Arduino IDE by using millis().
So I just copy pasted my code for a previous timer class I used for SDL programs and just replaced the SDL_GetTicks() with millis().
However, now it says millis() is out of scope. Which I dont understand? Am i not allowed to use millis inside member variables?
#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;
}
}
you have to include arduino.h in your header file, this should solve the problem.
#include <Arduino.h>