How do you reset an onboard timer??

Hi all, I'm having trouble resetting a timer. There is not an interrupt or hardware of any kind. You probably will tell me to look at BlinkWithoutDelay, but it's not working quite the way I want it to. Let me attempt to explain the way I want it to work. The timer itself is not in loop(). Rather, it is started when a sensor comes within a distance of an object. Once within the distance a separate function is called, starting a timer.

Here is my sample timer in a loop, no reset of timer :frowning:

unsigned long prevTime=0;
unsigned long curTime=0;
const int valinter = 750;

void setup()  {
  Serial.begin(9600);
}

void loop()  {
  Serial.println(curTime);
  curTime=millis();
  if( curTime > (prevTime + valinter) )  {
    curTime=curTime-valinter;
    return;
  }
}

Timer resets once and keeps going on like a diesel train the second time. How do I keep resetting after 3/4 of a second?

I was looking at topics like this before posting, and @AWOL had an interesting point that made sense. He was talking about 'offsetting' a timer rather than 'resetting' it per say. When setting the millis() variable to zero, it will read zeroes after the if statement is true.

Not good.

Attempted this 'offsetting' in the code above and again listed here:

curTime=curTime-valinter;

What about the following (not tested). It should print curTime after every 750msecs.
I'm not sure if that's what you want.
Your original code was not updating prevTime

unsigned long prevTime=0;
unsigned long curTime=0;
const int valinter = 750;

void setup()  {
  Serial.begin(9600);
}

void loop()  {
//  Serial.println(curTime);
  curTime=millis();
  if( curTime - prevTime > valinter )  {
    Serial.println(curTime);
    prevTime = prevTime + valinter;
  }
}

...R