Elapsed time since event (timer)

Hello, I'm working with an Arduino Uno. One part of the project is watching a pair of limit switches which will be pulled high when reached. The limit switches are on an actuated valve indicating either open or closed. I currently have the Arduino counting open events and closed events and printing them separately to a display. Now I would like to display the time elapsed since the last event. The same display line will be used regardless of the valve being open or closed "Time since last event: ".

I imagine this should be quite simple as I already have the event counter working. I just need a timer to begin when either counter increments. Then I need the timer to reset and begin timing anew the next time the counter increments, etc.

Use CTRL T to format your code.
Attach your current sketch between code tags </>.
[code]Paste your sketch here[/code]

I just need a timer to begin when either counter increments.

No, you don't. You just need to know when the value changes. Periodically, you calculate now minus then, to get the elapsed time that you want to show.

The millis() function is what everyone else uses.

Then I need the timer to reset

No, you don't.

You will NOT be using a timer.

Wellarmedlamb:
I imagine this should be quite simple as I already have the event counter working. I just need a timer to begin when either counter increments.

Save the value of millis() when the first event happens. Save (to another variable) the value of millis() when the second event happens. Subtract the first value from the second value to get the elapsed time.

There will be no need to reset millis() - you don’t ever reset the clock in your kitchen.

…R