Timer for accumulating 10 ms intervals that does not overflow after ~30 min

This class simply creates a timer that accumulates 10 millisecond intervals which does not overflow after about 30 min.

RunTimer.cpp

Committer:
jebradshaw
Date:
2016-05-19
Revision:
2:67e16d628edc
Parent:
1:134292d456c9
Child:
3:9efa965d2111

File content as of revision 2:67e16d628edc:

#include "RunTimer.h"

RunTimer::RunTimer(){
    this->ms=0;
    this->sec =0;
    this->min = 0;
    this->hour = 0;
    this->day = 0;
    
    this->timer_10ms.attach(this, &RunTimer::timeAcc, .01);
}

void RunTimer::timeAcc(void){
    this->ms +=10;
    if(this->ms == 1000){
        this->ms = 0;
        this->sec++;
        if(this->sec==60){
            this->sec=0;
            this->min++;
            if(this->min == 60){
                this->min=0;
                this->hour++;
                if(this->hour==24){
                    this->hour=0;
                    day++;
                }
            }
        }    
    }
}//timeAcc

void RunTimer::Reset(void){
    this->ms=0;
    this->sec =0;
    this->min = 0;
    this->hour = 0;
    this->day = 0;
}