#ifndef DIVIDER_H
#define DIVIDER_H

class Divider {
public:
    Divider(int interval = 1) {
	setInterval(interval);
    }
    void setInterval(int interval) {
	this->interval = interval;
	clockCounter = interval - 1;
    }
    void tick() {
	clockCounter++;
	if (clockCounter == interval) {
	    clockCounter = 0;
	}
    }
    bool hasClocked() {
	return clockCounter == 0;
    }

private:
    int interval;
    int clockCounter;
};

#endif

#ifndef DIVIDER_H
#define DIVIDER_H

class Divider {
public:
    Divider(int interval = 1) {
	setInterval(interval);
	reset();
    }
    void setInterval(int interval) {
	if (interval < 1) {
	    resetValue = 0;
	}
	else {
	    resetValue = interval - 1;
	}
    }
    void reset() {
	clockCounter = resetValue;
    }
    void tick() {
	if (clockCounter == 0) {
	    clockCounter = resetValue;
	}
	else {
	    --clockCounter;
	}
    }
    bool hasClocked() {
	return clockCounter == resetValue;
    }

private:
    int resetValue;
    int clockCounter;
};

#endif

Rewrite divider to change interval without resetting it
Rewrite divider to change interval without resetting it
