class Timer{
public:
Timer(){
}
void update(){
if(hasStarted){
now = millis();
if(now - timeEllapsed >= 10){
timeEllapsed = now;
time += 10;
Serial.println(time);
}
}
}
void start(){
hasStarted = true;
}
void stop(){
hasStarted = false;
}
unsigned long getTime(){
return time;
}
private:
unsigned long timeEllapsed;
unsigned long time;
unsigned long now;
bool hasStarted = false;
};
Timer timer;
void setup() {
Serial.begin(115200);
timer.start();
}
void loop() {
timer.update();
if(timer.getTime() >= 2000){
Serial.println("five seconds has passed");
timer.stop();
}
}