Hello guys!
I'm new here, but I've done a lot of research through posts and doubts, but still I couldn't understand pretty much how to use the millis() function, instead of delay().
I would like to someone answer these questions:
Let me give an example first:
unsigned long startTime = 0;
unsigned long endTime = 0;
void setup () {
// setup pins and stuffs
}
void loop () {
//Let's say i would like to blink a led after 2000 miliseconds, without using delay ()
digitalWrite (pin, HIGH); // I know pin does not exist, but it's just an example :)
endTime += 2000;
startTime = millis ();
if (startTime > endTime) {
digitalWrite (pin, LOW);
endTime = 0;
// reset millis() ?
}
}
I would like to understand how it works now:
1 I must refresh 'startTime' variable everytime I go on loop?
2 How to 'reset' millis () ?
3 I must declare some 'currentTime' variable in order to keep millis () working?
I appreciate if someone could help!
Thanks in advance!