delay/timer coding

hi

I am having a bit of difficulty applying the millis function to time a delay within some code.

Basically what I'm looking for is that when a specific scenario occurs, an output is set for a predefined time period.

I have already used the delay function and everything does 'work', but it could be better and more fluid.

any advice would be great.

thanks

Welcome to the Forum. We can't guess what your code does, so please post it. Please read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags which make the code looklike thiswhen posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.

I am having a bit of difficulty applying the millis function to time a delay within some code.

Advice on using millis() for timing. Save the millis() value at the time that the start action happens. Then, each time through loop(), check whether the required wait period has elapsed by subtracting the start time from the millis() value now. If the period has elapsed then act accordingly and maybe save the start time for the next activity. If not, then go round loop() again, perhaps taking other actions and/or reading inputs, but don't block the free running of loop().

hi thanks for the input.

I had been trying to do that but couldn't figure out how best to do it.
I have took your advice and I have progressed abit, however I am having difficulty clearing the saved value back to zero.

Post your code as it is now and describe the problem more fully.

You may find something useful in Several Things at a Time

...R

that was very helpful thank you