I'm not sure what the proper terminology would be for this, so it's been difficult to find the right library. Essentially I want to start a timer that'll run and not stop my code, like "delay" would do. What library would be appropriate for this?
I'm looking to do something like:
if(conditions == True)
{start.timer}
open launch doors, prepare rocket engines, etc. etc. do cool C++ stuff...
if (timer == X seconds)
{launch nukes, do more stuff}
millis() is a function that keeps track of how many milliseconds have passed since startup, and by taking a snapshot of it, and comparing that to the current value you can use as a timer.
unsigned long startTime = millis()
void loop()
{
if (millis() - startTime > 5000) // Has 5 seconds passed?
{
startTime = millis(); // Restart the timer.
// Do stuff
}
}
I plan to have the arduino on for a very long time, so I know millis has limits and eventually rolls over back to zero. Right? So would that still work for me?
From what I can see, the timer just keeps running. But what if I want to start and stop the timer? How do I do that when millis() is tracking how long the arudino has been running?
Well it was easier to use the library. I rarely write code, so I’ll stick with the library for now. If this comes up again later on a different project, I’ll do it the way you all suggested.